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
Unfortunately there seems to be an issue when using cURL in git-bash. On Linux, this asks the user for password and stores the cookie in COOKIE . In git-bash, issuing the command hangs, until using a " ctrl + C " to interrupt it.
Invoke curl.exe from a command window (in Windows, click Start > Run and then enter "cmd" in the Run dialog box). You can enter curl --help to see a list of cURL commands.
It's like apt-get in Linux, you can install using the command line. Run Command Prompt as Administrator and type choco install git and you'll be able to install git devoted to the command line.
With Windows 10 Insider build 17063 curl is available in the cmd and powershell since early 2018. Show activity on this post. Show activity on this post. Currently in Windows 10 build 17063 and later, cURL comes by default with windows.
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\"}\'") )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With