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