LSTANCZYK
2/12/2015 - 1:59 AM

HgSync.ps1

# powershell script for syncing a mercurial repository with a git repository.
# Usage: HgSync.ps1 NameOfProject git://github.com/Path/To/RemoteGitRepo.git https://Path/To/RemoteHgRepository
# Requires the hg-git plugin http://hg-git.github.com/

$project = $args[0]
$gitrepo = $args[1]
$hgrepo = $args[2]
$path = "D:\hg-sync\$project"

function hg {
  & "C:\Program Files (x86)\TortoiseHg\hg.exe" $args
}

write-host "Project: $project"
write-host "Git repo: $gitrepo"
write-host "Hg repo: $hgrepo"
write-host
write-host

if(test-path $path) {
  write-host "Directory $path exists. Performing update..."
  write-host
  pushd $path
  hg pull
  hg update
  write-host "Pushing to hg repo..."
  write-host
  hg push -b . hgrepo
  popd
}
else {
  write-host "Directory $path does not exist. Performing clone..."
  write-host
  [void](mkdir $path)  
  hg clone $gitrepo $path
  pushd $path
  write-host
  write-host "Adding hg path..."
  add-content .hg\hgrc "`nhgrepo = $hgrepo"
  write-host "Pushing to hg repo..."
  write-host
  hg push -b . hgrepo
  popd
}

write-host
write-host "Done."