Compare commits
No commits in common. "master" and "0.1.0" have entirely different histories.
@ -24,12 +24,8 @@ proc `$`(buf: OutputBuffer): string =
|
|||||||
buf.outBuf.join("\n") & "\n" & buf.errBuf.join("\n")
|
buf.outBuf.join("\n") & "\n" & buf.errBuf.join("\n")
|
||||||
|
|
||||||
proc git(repoDir: string, args: openArray[string]): bool =
|
proc git(repoDir: string, args: openArray[string]): bool =
|
||||||
if verbose:
|
let res = exec("git", repoDir, args, env, {poUsePath}, outputHandler)
|
||||||
stdout.setForegroundColor(fgBlue, false)
|
return res.exitCode == 0
|
||||||
stdout.writeLine("> git " & toSeq(args.items).mapIt("'" & it & "'").join(" "))
|
|
||||||
stdout.resetAttributes()
|
|
||||||
|
|
||||||
return exec("git", repoDir, args, env, {poUsePath}, outputHandler) == 0
|
|
||||||
|
|
||||||
proc isGitRepo(dir: string): bool =
|
proc isGitRepo(dir: string): bool =
|
||||||
if not existsDir(dir): return false
|
if not existsDir(dir): return false
|
||||||
@ -64,11 +60,9 @@ Options:
|
|||||||
-V --version Print version
|
-V --version Print version
|
||||||
-r --remote <remote> Pull from <remote> (defaults to "origin")
|
-r --remote <remote> Pull from <remote> (defaults to "origin")
|
||||||
-b --branch <branch> Pull the <branch> branch (defaults to "master")
|
-b --branch <branch> Pull the <branch> branch (defaults to "master")
|
||||||
-o --log-out <outlog> Log command output to <outfile>
|
|
||||||
-e --log-err <errlog> Log error output to <errfile>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
let args = docopt(doc, version = "git_pull_all 0.2.1")
|
let args = docopt(doc, version = "git_pull_all 0.1.0")
|
||||||
|
|
||||||
let rootDirs: seq[string] =
|
let rootDirs: seq[string] =
|
||||||
if args["<root>"]: args["<root>"].mapIt(it)
|
if args["<root>"]: args["<root>"].mapIt(it)
|
||||||
@ -94,19 +88,9 @@ Options:
|
|||||||
outputHandler = combineProcMsgHandlers(outputHandler,
|
outputHandler = combineProcMsgHandlers(outputHandler,
|
||||||
makeProcMsgHandler(stdout, stderr))
|
makeProcMsgHandler(stdout, stderr))
|
||||||
|
|
||||||
var outLog, errLog: File = nil
|
|
||||||
if args["--log-out"]: outLog = open($args["<outlog>"], fmRead)
|
|
||||||
if args["--log-err"]: errLog = open($args["<errlog>"], fmRead)
|
|
||||||
|
|
||||||
if outLog != nil or errLog != nil:
|
|
||||||
outputHandler = combineProcMsgHandlers(outputHandler,
|
|
||||||
makeProcMsgHandler(outLog, errLog))
|
|
||||||
|
|
||||||
# Foreach repo:
|
# Foreach repo:
|
||||||
for repoDir in repos:
|
for repoDir in repos:
|
||||||
let repoName = repoDir.extractFilename
|
let repoName = repoDir.extractFilename
|
||||||
|
|
||||||
if verbose: stdout.writeLine("")
|
|
||||||
stdout.setForegroundColor(fgCyan, true)
|
stdout.setForegroundColor(fgCyan, true)
|
||||||
stdout.write("Pulling ")
|
stdout.write("Pulling ")
|
||||||
stdout.setForegroundColor(fgYellow, false)
|
stdout.setForegroundColor(fgYellow, false)
|
||||||
@ -118,31 +102,13 @@ Options:
|
|||||||
failRepos.add((repoName, reason))
|
failRepos.add((repoName, reason))
|
||||||
writeErrMsg(reason)
|
writeErrMsg(reason)
|
||||||
|
|
||||||
var pullOutput: seq[string]
|
# Is the repo clean? No -> fail to pull this repo
|
||||||
|
|
||||||
# Is the a bare repo clean?
|
|
||||||
cmdOutput.clear()
|
cmdOutput.clear()
|
||||||
if not git(repoDir, ["status"]):
|
if not git(repoDir, ["status"]) or
|
||||||
|
cmdOutput.outBuf.join("\n").find("working tree clean") < 0:
|
||||||
# pull --ff-only
|
failRepo("working directory is not clean")
|
||||||
if not git(repoDir, ["pull", "--ff-only", remote, branch]):
|
|
||||||
failRepo("unable to ffwd branch")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pullOutput = cmdOutput.outBuf
|
|
||||||
|
|
||||||
# Not bare
|
|
||||||
else:
|
|
||||||
# Not clean? Try to stash the changes.
|
|
||||||
var stashed = false
|
|
||||||
if cmdOutput.outBuf.join("\n").find("working tree clean") < 0 and
|
|
||||||
cmdOutput.outBuf.join("\n").find("working directory clean") < 0:
|
|
||||||
cmdOutput.clear()
|
|
||||||
if not git(repoDir, ["stash", "save"]):
|
|
||||||
failRepo("error trying to stash uncommitted changes")
|
|
||||||
continue
|
|
||||||
else: stashed = true
|
|
||||||
|
|
||||||
# Are we on the correct branch?
|
# Are we on the correct branch?
|
||||||
cmdOutput.clear()
|
cmdOutput.clear()
|
||||||
if not git(repoDir, ["branch"]):
|
if not git(repoDir, ["branch"]):
|
||||||
@ -165,23 +131,7 @@ Options:
|
|||||||
failRepo("unable to ffwd branch")
|
failRepo("unable to ffwd branch")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pullOutput = cmdOutput.outBuf
|
if cmdOutput.outBuf.anyIt(it.find("Already up-to-date") > 0):
|
||||||
|
|
||||||
# restore original branch
|
|
||||||
if currentBranch != branch:
|
|
||||||
if not git(repoDir, ["checkout", currentBranch]):
|
|
||||||
stdout.setForegroundColor(fgWhite, true)
|
|
||||||
stdout.writeLine("WARNING: unable to checkout original branch (" & currentBranch & ")")
|
|
||||||
stdout.resetAttributes()
|
|
||||||
|
|
||||||
# restore stashed changes
|
|
||||||
if stashed:
|
|
||||||
if not git(repoDir, ["stash", "pop"]):
|
|
||||||
stdout.setForegroundColor(fgWhite, true)
|
|
||||||
stdout.writeLine("WARNING: unable to pop stashed changes")
|
|
||||||
stdout.resetAttributes()
|
|
||||||
|
|
||||||
if pullOutput.anyIt(it.find("Already up-to-date") > 0):
|
|
||||||
stdout.setForegroundColor(fgBlack, true)
|
stdout.setForegroundColor(fgBlack, true)
|
||||||
stdout.writeLine("already up-to-date")
|
stdout.writeLine("already up-to-date")
|
||||||
else:
|
else:
|
||||||
@ -190,5 +140,12 @@ Options:
|
|||||||
stdout.resetAttributes()
|
stdout.resetAttributes()
|
||||||
successRepos.add(repoName)
|
successRepos.add(repoName)
|
||||||
|
|
||||||
|
# restore original branch
|
||||||
|
if currentBranch != branch:
|
||||||
|
if not git(repoDir, ["checkout", currentBranch]):
|
||||||
|
stdout.setForegroundColor(fgWhite, true)
|
||||||
|
stdout.writeLine("WARNING: unable to checkout original branch (" & currentBranch & ")")
|
||||||
|
stdout.resetAttributes()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
stderr.writeLine "git_pull_all: " & getCurrentExceptionMsg()
|
stderr.writeLine "git_pull_all: " & getCurrentExceptionMsg()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.2.1"
|
version = "0.1.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Small CLI utility to pull multiple git repos."
|
description = "Small CLI utility to pull multiple git repos."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -10,4 +10,4 @@ bin = @["git_pull_all"]
|
|||||||
|
|
||||||
requires @["nim >= 0.16.1", "docopt >= 0.6.4"]
|
requires @["nim >= 0.16.1", "docopt >= 0.6.4"]
|
||||||
|
|
||||||
requires "https://git.jdb-labs.com/jdb/nim-cli-utils.git >= 0.3.0"
|
requires "https://git.jdb-labs.com/jdb/nim-cli-utils.git"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user