]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
script/ptl-tool: get git dir via git command 68639/head
authorPatrick Donnelly <pdonnell@redhat.com>
Mon, 27 Apr 2026 19:37:43 +0000 (15:37 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 28 Apr 2026 14:24:47 +0000 (10:24 -0400)
Rather than a manual process.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/script/ptl-tool.py

index 4848190f12b5cb4861cbaddce6f0e170c2a1ac63..ef98e272e5483d9469946ce3fd143689c8a62e27 100755 (executable)
@@ -227,13 +227,10 @@ log.addHandler(logging.StreamHandler())
 log.setLevel(logging.INFO)
 
 # find containing git dir
-git_dir = GITDIR
-max_levels = 6
-while not os.path.exists(git_dir + '/.git'):
-    git_dir += '/..'
-    max_levels -= 1
-    if max_levels < 0:
-        break
+try:
+    git_dir = git.Repo(GITDIR, search_parent_directories=True).working_tree_dir
+except (git.NoSuchPathError, git.InvalidGitRepositoryError) as e:
+    raise SystemExit(f"error: not a git repository: {GITDIR}") from e
 
 CONTRIBUTORS = {}
 NEW_CONTRIBUTORS = {}