简体   繁体   中英

using git and curl command line

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 .

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]
    }
}

I then try it with 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)

And get the message:

> 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 

How can I run this command:

curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}' from the console.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM