R/CloneProject.R

Defines functions CloneProject

Documented in CloneProject

#' @title Clone an existing project repository
#'
#' @description Clones an existing version controlled
#' repository to your local drive.  If both repo.dir and local.dir are not given then a folder browser will open to navigate the users directories.
#'
#'
#'
#' @param repo.dir Absolute path to the repository.  This must be a folder that has a .git extension.
#' @param local.dir Absolute path to the local parent directory
#'  where you want your copy of the project to live.
#' The function will create a new folder with the same name
#' as the repository.
#'
#'
#' @usage CloneProject(repo.dir=NULL,local.dir=NULL)
#'
#' @examples
#' \donttest{
#' CloneProject(repo.dir="Z:/Biostat/ProjectRepo.git", local.dir="C:/Projects/")
#'
#' }
#'
#' @export
#' @name CloneProject
#' @author Dominic LaRoche
#'
CloneProject<-function(repo.dir=NULL, local.dir=NULL){

#   if(is.null(repo.dir)|is.null(local.dir)){
#     stop("You must specify both a repository and local directory")
#   }
  if(is.null(repo.dir)){
    repo.dir<-choose.dir(caption="Choose the repository parent directory")
  }
  if(is.null(local.dir)){
    local.dir<-choose.dir(caption="Choose the local directory")
  }
  #Check to ensure file paths have a trailing forward slash (but only 1)
  if(!grepl(".+\\.git$", repo.dir, perl=TRUE)){
    stop("You must specify a Git repository (folder with .git extension)")
  }
  if(!grepl(".+/$", local.dir, perl=TRUE)){
    local.dir<-paste0(local.dir,"/")
  }
  name<-gsub("\\\\", "/", repo.dir)
  name<-gsub(".*(/.+)\\.git$", "\\1", name)
  print(name)
  #create local clone
  clone.cmd<- paste0("git clone --origin master ", " ", repo.dir, " ", local.dir, name)
  shell(clone.cmd, shell="cmd.exe")

}
rocrat/HTGPackage documentation built on May 25, 2017, 8:32 a.m.