Skip to content

Commit b441bef

Browse files
committed
Fix annoying warnings when running in a container
This is a follow-up to 07f28a4 which added support for figuring out the GIT revision when 9pm is a submodule in another proejct. However, that project in turn may be a git worktree, where the actual .git directory is elsewhere, and when said project is running its tests from a Docker container, things get worse. It is very likely that the actual .git directory is unreachable from within the container. This patch hides the following annoying warnings: warning, git command failed (Command '['git', '--git-dir', '/home/jocke/src/x-misc/test/9pm/../../../infix/.git/worktrees/x-misc/modules/9pm', 'rev-parse', 'HEAD']' returned non-zero exit status 128.) 9PM - Simplicity is the ultimate sophistication warning, git command failed (Command '['git', '--git-dir', '/home/jocke/src/infix/.git/worktrees/x-misc', 'rev-parse', 'HEAD']' returned non-zero exit status 128.) Testing Infix Running suite 0001 all.yaml Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 6b286b9 commit b441bef

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

9pm.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,20 +808,21 @@ def run_git_cmd(path, command):
808808
with open(git_path, 'r') as f:
809809
line = f.read().strip()
810810
if line.startswith('gitdir: '):
811-
gitdir = os.path.join(path, line[8:])
811+
git_path = os.path.join(path, line[8:])
812+
if not os.path.exists(git_path):
813+
return ""
812814
else:
813815
vcprint(pcolor.orange, f"warning, invalid .git file format ({path})")
814816
return ""
815-
elif os.path.isdir(git_path):
816-
gitdir = git_path
817-
else:
817+
818+
if not os.path.isdir(git_path):
818819
vcprint(pcolor.orange, f"warning, no .git dir or file in path ({path})")
819820
return ""
820821

821822
try:
822-
vcprint(pcolor.faint, f"Running: git --git-dir {gitdir} {command}")
823+
vcprint(pcolor.faint, f"Running: git --git-dir {git_path} {command}")
823824
result = subprocess.check_output(
824-
['git', '--git-dir', gitdir] + command,
825+
['git', '--git-dir', git_path] + command,
825826
stderr=subprocess.STDOUT
826827
).decode('utf-8').strip()
827828
except Exception as e:

0 commit comments

Comments
 (0)