Created
November 2, 2013 17:20
-
-
Save philchalmers/7281255 to your computer and use it in GitHub Desktop.
Function to convert an existing R-forge svn repository to git.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Convert the trunk of an R-forge SVN repository to git | |
#' | |
#' This function to reorganizes an existing svn repository from R-forge to a git repository. One | |
#' or both of the repository paths can be specified. Assumes that git-svn has been installed, and | |
#' that git can be called through the command line/terminal. Windows users may have to | |
#' add the git binary location to their ENVIRONMENTAL VARIABLES. | |
#' | |
#' @param svn.repo a string pointing to the R-forge svn repository. Generally of the form | |
#' \code{svn://svn.r-forge.r-project.org/svnroot/package/} or | |
#' \code{svn+ssh://developername@@svn.r-forge.r-project.org/svnroot/package/}. This will reorganize | |
#' the format into something more suitable for github or gitorioius | |
#' @param git.repo a remote location to push the git repository to | |
#' @param rev_num specific revision number. Use to make a specific cloning point from the svn | |
#' repo. Default is to clone the entire repo | |
#' @param clean logical; remove extra material in the svn repo? | |
#' | |
#' @examples | |
#' \dontrun{ | |
#' | |
#' # convert R-forge tableplot to git | |
#' svn.repo <- 'svn://svn.r-forge.r-project.org/svnroot/tableplot/' | |
#' rforge2git(svn.repo=svn.repo) | |
#' | |
#' # publish to an empty git remote location | |
#' # (Note: this will not work on your computer since you must be an admin for the git repo) | |
#' git.repo <- 'https://github.com/philchalmers/svntableplot.git' | |
#' rforge2git(git.repo=git.repo) | |
#' | |
#' #run both steps at once | |
#' rforge2git(svn.repo=svn.repo, git.repo=git.repo) | |
#' | |
#' } | |
rforge2git <- function(svn.repo = NULL, git.repo = NULL, rev_num = NULL, clean = TRUE){ | |
if(is.null(svn.repo) && is.null(git.repo)) | |
stop('One or both of svn.repo or git.repo must be specified.') | |
if(!is.null(svn.repo)){ | |
dir <- dir() | |
if(is.numeric(rev_num)){ | |
gc <- sprintf('git svn clone -r %i:HEAD', rev_num) | |
} else gc <- 'git svn clone ' | |
system(paste0(gc, svn.repo)) | |
reponame <- setdiff(dir(), dir) | |
setwd(reponame) | |
if(clean) system(paste0(c('rm -f -r', setdiff(dir(), 'pkg')), collapse=" ")) | |
is_win <- Sys.info()['sysname'] == 'Windows' | |
if(is_win){ | |
wd <- getwd() | |
wd <- gsub('/', '\\\\', wd) | |
system(paste0('xcopy pkg ', paste0(wd, ' /s /e /h'))) | |
system('rm -f -r pkg') | |
} else { | |
system('git mv pkg/* pkg/.[a-zA-Z]* .') | |
system('rmdir pkg/') | |
} | |
system('touch README.md') | |
system('git add --all') | |
system('git commit -m "fixup initial migration from svn"') | |
} | |
# option to publish git repo | |
if(!is.null(git.repo)){ | |
system(paste0('git remote add origin ', git.repo)) | |
system('git push -u origin master') | |
} | |
return(invisible(NULL)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment