在Windows上使用R将本地repo推送到github
我曾经问过一个非常
similar question,并得到了从命令行工作的响应,但现在我想使用R来自Windows的进程自动化(Linux更容易).
这是我要做的: >创建本地目录(或已存在) 我相信based on the output,在我失败之前,我得到了所有的方法到第5步(因为本地目录中的提交和文件不会在云中的github).我知道步骤2的工作原因是空的repo被创建here.我不知道如何测试步骤5.在最后一步shell(cmd6,intern = T)RGui和RStudio导致永恒的死亡螺旋.问题是:我如何将提交和本地的回购推送到云端. 这是我更新的代码(唯一的用户特定的是第三个代码块中的用户名和密码): ## 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 = ","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/","/",".git") shell(cmd5,intern = T) ## push local to remote cmd6 <- paste0(shQuote(gitpath)," push -u origin master") shell(cmd6,intern = T) setwd(wd) 我知道脚本有点长,但是重新创建问题和复制问题都是必要的: 注意我已经根据Simon的回应更新了这个问题,因为他是正确的,并且更接近于推动.原题的内容可以在here找到.
如果使用https地址,请确保:
>定义环境变量%HOME% 该文件包含: machine github.com login username password xxxx protocol https 即使你有activated the recent two-factor authentication on GitHub也是如此. 那么你的推动不会超时: cmd6 <- paste0(shQuote(gitpath),intern = T) 这比setting public/private ssh keys更容易. 作为OP Tyler Rinker commented,设置%HOME%在我的其他答案“Git – How to use if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH% @if not exist "%HOME%" @set HOME=%USERPROFILE% 但是您也可以手动进行操作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 简单安装windows terminal和在window10开启Ubunt
- windows – IE8是否已为企业环境做好准备?
- windows-server-2003 – 远程附加域控制器
- 是否有“Microsoft”外观的标准WPF样式表?
- winapi – 为什么我的Win32 gdi游戏在Windows 7上
- windows – 在多个服务器上查询EXE详细信息
- windows – 批处理脚本:验证日期输入
- 在Windows 7中,使用ActivePerl @ARGV为空
- 为vagrant windows box更正“config.ssh.shell”
- 如何强制执行Office 365自定义“角色分配策略”默