Skip to content

Commit f021fed

Browse files
committed
Add support for running self-tests when 9pm is a submodule
When working on 9PM while it is used as a GIT submodule in another project, .git is not a directory. Handle this case by looking up the actual .git directory: $ ls -la .git -rw-rw-r-- 1 bob bob 31 dec 1 2023 .git $ cat .git gitdir: ../../.git/modules/9pm Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 773bac3 commit f021fed

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

9pm.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,20 @@ def setup_env(args):
771771
os.environ["NINEPM_CONFIG"] = args.config
772772

773773
def run_git_cmd(path, command):
774-
gitdir = os.path.join(path, '.git')
774+
git_path = os.path.join(path, '.git')
775775

776-
if not os.path.isdir(gitdir):
777-
vcprint(pcolor.orange, f"warning, no .git dir in path ({path})")
776+
if os.path.isfile(git_path):
777+
with open(git_path, 'r') as f:
778+
line = f.read().strip()
779+
if line.startswith('gitdir: '):
780+
gitdir = os.path.join(path, line[8:])
781+
else:
782+
vcprint(pcolor.orange, f"warning, invalid .git file format ({path})")
783+
return ""
784+
elif os.path.isdir(git_path):
785+
gitdir = git_path
786+
else:
787+
vcprint(pcolor.orange, f"warning, no .git dir or file in path ({path})")
778788
return ""
779789

780790
try:

0 commit comments

Comments
 (0)