Una volta ho chiesto un similar question e ricevuto una risposta che ha lavorato dalla linea di comando, ma ora sto volendo utilizzare R per automatizzare il processo da Windows (Linux è molto più facile).Usa R per spingere repo locale per GitHub su Windows
Ecco quello che sto cercando di fare:
- Creare una directory locale (o già esistente)
- generare una nuova repo github nel cloud con lo stesso nome come locali (based on this answer)
- Aggiungi un .git al repo locale
- Fai iniziale commettere
- stabilire un collegamento tra la nuvola pronti contro termine e pronti contro termine locale
- Spingere il commit ei file nel repository locale per GitHub
Credo based on the output che ho tutta la strada al punto 5, prima di fallire (come il commettono e file dalla directory locale non vanno mai a github nel nube). So che il passaggio 2 funziona perché viene creato il repository vuoto here. Non so come testare il passaggio 5. All'ultimo step shell(cmd6, intern = T)
RGui e RStudio danno origine a una spirale di morte eterna. La domanda è: Come posso spingere il commit e il repo locale sul cloud.
Ecco il mio codice aggiornato (l'unica cosa che è specifico dell'utente è username e password nel terzo codice pezzo):
## Create Directory
repo <- "foo5"
dir.create(repo)
project.dir <- file.path(getwd(), repo)
## Throw a READ.ME in the directory
cat("This is a test", file=file.path(project.dir, "READ.ME"))
## Github info (this will change per user)
password <-"pass"
github.user <- "trinker"
## Get git location
test <- c(file.exists("C:/Program Files (x86)/Git/bin/git.exe"),
file.exists("C:/Program Files/Git/bin/git.exe"))
gitpath <- c("C:/Program Files (x86)/Git/bin/git.exe",
"C:/Program Files/Git/bin/git.exe")[test][1]
## download curl and set up github api
wincurl <- "http://curl.askapache.com/download/curl-7.32.0-win64-ssl-sspi.zip"
url <- wincurl
tmp <- tempfile(fileext = ".zip")
download.file(url,tmp)
unzip(tmp, exdir = tempdir())
shell(paste0(tempdir(), "/curl http://curl.haxx.se/ca/cacert.pem -o " ,
tempdir() , "/curl-ca-bundle.crt"))
json <- paste0(" { \"name\":\"" , repo , "\" } ") #string we desire formatting
json <- shQuote(json , type = "cmd")
cmd1 <- paste0(tempdir() ,"/curl -i -u \"" , github.user , ":" , password ,
"\" https://api.github.com/user/repos -d " , json)
shell(cmd1, intern = T)
## Change working directory
wd <- getwd()
setwd(project.dir)
## set up the .git directory
cmd2 <- paste0(shQuote(gitpath), " init")
shell(cmd2, intern = T)
## add all the contents of the directory for tracking
cmd3 <- paste0(shQuote(gitpath), " add .")
shell(cmd3, intern = T)
cmdStat <- paste0(shQuote(gitpath), " status")
shell(cmdStat, intern = T)
## Set email (may not be needed)
Trim <- function (x) gsub("^\\s+|\\s+$", "", x) #remove trailing/leading white
x <- file.path(path.expand("~"), ".gitconfig")
if (file.exists(x)) {
y <- readLines(x)
email <- Trim(unlist(strsplit(y[grepl("email = ", y)], "email ="))[2])
} else {
z <- file.path(Sys.getenv("HOME"), ".gitconfig")
if (file.exists(z)) {
email <- Trim(unlist(strsplit(y[grepl("email = ", y)], "email ="))[2])
} else {
warning(paste("Set `email` in", x))
}
}
cmdEM <- paste0(shQuote(gitpath), sprintf(" config --global user.email %s", email))
system(cmdEM, intern = T)
## Initial commit
cmd4 <- paste0(shQuote(gitpath), ' commit -m "Initial commit"')
system(cmd4, intern = T)
## establish connection between local and remote
cmd5 <- paste0(shQuote(gitpath), " remote add origin https://github.com/",
github.user, "/", repo, ".git")
shell(cmd5, intern = T)
## push local to remote
cmd6 <- paste0(shQuote(gitpath), " push -u origin master")
shell(cmd6, intern = T)
setwd(wd)
So che la sceneggiatura è un po 'più lungo ma è tutto necessario per ricreare il problema e replicare il problema:
Nota Ho aggiornato la domanda alla luce della risposta di Simon poiché era corretto e si avvicinava alla spinta. Il contenuto della domanda originale può essere trovato here.
Il repository appare ok? Potrebbe essere un problema con Windows che blocca i file e non lasciar andare. Prova anche a cambiare 'cmd3' in' paste0 (shQuote (gitpath), "add -all") 'e poi anche a eseguire' paste0 (shQuote (gitpath), "status") 'subito dopo. ** E ** potresti voler mettere un interruttore per determinare la piattaforma e se su Windows usa 'shell' not' system'. Trovo 'shell' per essere un po 'più amichevole su' Windows'. –
Secondo la mia esperienza, è quasi sempre meglio usare 'system' e non' shell'. – hadley