gitPull non-master default branch, rmFile fix

This commit is contained in:
Ganesh Viswanathan 2020-07-03 23:51:52 -05:00
commit 03d1b54d6c

View file

@ -155,7 +155,7 @@ proc rmFile*(source: string, dir = false) =
if dir: if dir:
"rd /s/q" "rd /s/q"
else: else:
"del /s/q/f" "del /q/f"
else: else:
"rm -rf" "rm -rf"
exists = exists =
@ -335,6 +335,18 @@ proc gitAtCheckout*(outdir, checkout: string): bool =
result = checkout in execAction( result = checkout in execAction(
&"cd {outdir.sanitizePath} && git log --decorate --no-color -n 1 --format=oneline").output &"cd {outdir.sanitizePath} && git log --decorate --no-color -n 1 --format=oneline").output
proc gitDefaultBranch*(outdir: string): string =
## Get the default branch for a git repository before it is pulled
result = "master"
let
output = execAction(
&"cd {outdir.sanitizePath} && git remote show origin"
).output
for line in output.splitLines():
if "HEAD branch: " in line:
result = line.split("branch: ")[1].strip()
proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false) = proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false) =
## Pull the specified git repository to the output directory ## Pull the specified git repository to the output directory
## ##
@ -375,15 +387,14 @@ proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false
# In case directory has old files from another run # In case directory has old files from another run
discard execAction(&"cd {outdirQ} && git clean -fxd") discard execAction(&"cd {outdirQ} && git clean -fxd")
if checkout.len != 0: # Checkout specified branch/tag/commit or default branch - typically master
if not quiet: let
gecho "# Checking out " & checkout checkout = if checkout.Bl: gitDefaultBranch(outdir) else: checkout
discard execAction(&"cd {outdirQ} && git fetch", retry = 3)
discard execAction(&"cd {outdirQ} && git checkout {checkout}") if not quiet:
else: gecho "# Checking out " & checkout
if not quiet: discard execAction(&"cd {outdirQ} && git fetch", retry = 3)
gecho "# Pulling repository" discard execAction(&"cd {outdirQ} && git checkout {checkout}")
discard execAction(&"cd {outdirQ} && git pull --depth=1 origin master", retry = 3)
proc gitTags*(outdir: string): seq[string] = proc gitTags*(outdir: string): seq[string] =
## Get all the git tags in the specified directory ## Get all the git tags in the specified directory