【问题标题】:using git and curl command line使用 git 和 curl 命令行
【发布时间】: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 的经验为零,github Gem 在那里不工作吗?

标签: windows r git curl


【解决方案1】:

在我看来,您似乎正在尝试将 curl 作为 git 命令 system("git curl") 运行,这显然是行不通的。我认为您需要以类似于您对上面的 Git 可执行文件所做的方式在 Windows 上找到 curl 二进制文件的安装路径。在 Mac OS X 上,您可以像这样运行命令...

system("curl -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'")

记住要转义字符串中多余的引号。

我猜你甚至可以只下载 curl 的编译二进制文件并从下载位置运行它?我无法在工作中使用我的 Win7 机器来测试这个复制和粘贴的运行,但你明白了......

url <- "http://curl.askapache.com/download/curl-7.23.1-win64-ssl-sspi.zip"
tmp <- tempfile( fileext = ".zip" )
download.file(url,tmp)
unzip(tmp)
system( paste0( tempdir(),"/curl", " -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'") )

【讨论】:

猜你喜欢
  • 2018-03-18
  • 2018-11-16
  • 1970-01-01
  • 2013-02-19
  • 2013-04-18
  • 2013-01-01
  • 2013-08-11
  • 1970-01-01
  • 2017-06-28
相关资源
最近更新 更多