【发布时间】:2013-02-22 22:44:37
【问题描述】:
我正在尝试编写一个函数来将项目推送到 github,而无需先在云中创建项目。目前,您可以使用来自this question 的信息从 RStudio 中的 git 命令行执行此操作。
现在我正在尝试将其包装成一个函数,我可以使用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 放在前面就跑。我目前在 win 7 机器上
【问题讨论】:
-
你安装了 curl 吗?
-
如果我可以运行 RCurl,我想我会这样做。 linux上没试过。我想小技巧是在 Windows 上找到它。
-
@hadley 我可以使用 git 命令行来完成,所以必须安装 curl(虽然我找不到它)。
-
我在 Windows 上使用 Ruby 的经验为零,
githubGem 在那里不工作吗?