我正在嘗試編寫一個函數來將項目推送到github,而無需先在雲中創建項目。目前,您可以使用來自this question的信息從RStudio中的git命令行執行此操作。使用git和curl命令行
現在我試圖將它包裝到一個函數中,我可以使用system
在本地回購庫中創建雲中的回購。我正在通過Windows和Linux機器上的這個工作(所以不知道它在mac上的效果如何)。這裏是我的代碼迄今(檢測git的位置):
gitpath <- NULL
repo <- "New"
user <- "CantPostThat"
password <- "blargcats"
if (Sys.info()["sysname"] != "Windows") {
gitpath <- "git"
} else {
if (is.null(gitpath)){
test <- c(file.exists("C:\\Program Files (x86)\\Git\\bin\\git.exe"),
file.exists("C:\\Program Files\\Git\\bin\\git.exe"))
if (sum(test) == 0) {
stop("Git not found. Supply path to 'gitpath'")
}
gitpath <- c("\"C:\\Program Files (x86)\\Git\\bin\\git\"",
"\"C:\\Program Files\\Git\\bin\\git\"")[test][1]
}
}
然後,我system
嘗試:
system(paste(gitpath, "--version"))
> system(paste(gitpath, "--version"))
git version 1.7.11.msysgit.1
看起來不錯。但後來我嘗試在一個真正的代碼塊:
cmd1 <- paste(gitpath, paste0("curl -u '", user, ":", password,
"' https://api.github.com/user/repos -d '{\"name\":\"", repo, "\"}'"))
system(cmd1)
,看到消息:
> system(cmd1)
git: 'curl' is not a git command. See 'git --help'.
Did you mean this?
pull
Warning message:
running command '"C:\Program Files (x86)\Git\bin\git" curl -u ' trinker : PASSWORD ' https://api.github.com/user/repos -d '{"name":" three "}'' had status 1
我怎樣才能運行此命令:
curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}'
從控制檯。
我也試過沒有把git先放在前面。我目前在贏7機
你有捲曲安裝? – hadley 2013-02-23 00:53:00
我想我可以運行RCurl。還沒有嘗試過在Linux上。我想這個小故事會在windows上找到它。 – 2013-02-23 02:17:06
@hadley我可以用git命令行來完成,所以必須安裝curl(儘管我找不到它)。 – 2013-02-23 02:53:03