使用git和curl命令行 [英] using git and curl command line

查看:188
本文介绍了使用git和curl命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个函数来将项目推送到github,而无需先在云中创建项目。目前,您可以使用此问题中的信息从RStudio中的git命令行执行此操作。

I'm trying to write a function to push a project to github without first creating the project in the clouds. Currently you can do this from the git command line in RStudio using info from this question.

现在我试图将它包装到一个函数中,我可以使用 system 创建repo从一个地方回购的云彩。我正在通过这个在Windows和linux机器(所以不知道这是如何工作在Mac上)。这里是我的代码到目前为止(检测git位置):

Now I'm trying to wrap it up into a function that I can use system to create the repo in the clouds from a local repo. I am working through this on a Windows and linux machine (so not sure how well this works on mac yet). Here's my code thus far (detect git location):

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

看起来不错。但是,然后我尝试一个真正的代码块:

Looks good. But then I try it on a real code chunk:

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机器

I also tried running without putting git in front first. I'm currently on a win 7 machine

推荐答案

在我看来,你试图运行curl作为一个git命令 system(git curl)这显然不会工作。我想你需要找到在Windows上curl二进制文件的安装路径,其方式类似于使用上面的Git可执行文件。在Mac OS X你可以运行你的命令像这样...

To my mind it looks like you are trying to run curl as a git command system("git curl") which obviously won't work. I think you need to find the install path of the curl binary on Windows in a manner similar to what you did with the Git executable above. On Mac OS X you can run your command like so...

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

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

Remembering to escape the extra quotation marks in the string.

你甚至可以只下载编译的二进制curl并从下载位置运行它?我没有访问我的Win7盒在工作测试这个运行从复制和粘贴,但你得到的想法...

I guess you could even just download the compiled binary of curl and run it from the download location? I haven't got access to my Win7 box at work to test this runs from copy and paste but you get the idea...

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\"}\'") )

这篇关于使用git和curl命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆