using git and curl command line

14,732

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\"}\'") )
Share:
14,732
Tyler Rinker
Author by

Tyler Rinker

I’m a husband and father of 2 girls. I lead data scientce @ Anthology, #Python &amp; #rstats enthusiast, #dataviz geek, and #nlp buff.

Updated on June 19, 2022

Comments

  • Tyler Rinker
    Tyler Rinker almost 2 years

    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

  • Tyler Rinker
    Tyler Rinker about 11 years
    This answered the question but I still can't get it to work. I'm marking as correct and asking a more appropriate question -here- (I wasn't even asking the right question in this thread).