tools/deps: fix git dir check (#15470)

On Windows, a successful call will have a trailing newline appended, so
strip that away before doing any checks.
This commit is contained in:
alaviss
2020-10-02 11:52:20 -05:00
committed by GitHub
parent ff70ff529d
commit e3eae3f7c7

View File

@@ -1,4 +1,4 @@
import os, uri, strformat, osproc
import os, uri, strformat, osproc, strutils
proc exec(cmd: string) =
echo "deps.cmd: " & cmd
@@ -14,7 +14,11 @@ proc isGitRepo(dir: string): bool =
# Using this, we can verify whether a folder is a git repository by checking
# whether the command success and if the output is empty.
let (output, status) = execEx fmt"git -C {quoteShell(dir)} rev-parse --show-cdup"
result = status == 0 and output == ""
# On Windows there will be a trailing newline on success, remove it.
# The value of a successful call typically won't have a whitespace (it's
# usually a series of ../), so we know that it's safe to unconditionally
# remove trailing whitespaces from the result.
result = status == 0 and output.strip() == ""
const commitHead* = "HEAD"