-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy path0001-git-Use-show-prefix-instead-of-show-toplevel-for-fin.patch
67 lines (61 loc) · 2.36 KB
/
0001-git-Use-show-prefix-instead-of-show-toplevel-for-fin.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From daea9d0548767ba48d8fb407859db5a8dc8280c7 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <[email protected]>
Date: Fri, 29 Jan 2021 16:52:43 +0100
Subject: [PATCH] git: Use --show-prefix instead of --show-toplevel for finding
the git root
--show-prefix works with relative paths which also works with cygwin git,
while --show-toplevel would return absolute Unix paths which Python
doesn't know anything about.
---
src/setuptools_scm/file_finder_git.py | 11 +++++++++--
src/setuptools_scm/git.py | 9 ++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/setuptools_scm/file_finder_git.py b/src/setuptools_scm/file_finder_git.py
index 1d3e69b..ac060aa 100644
--- a/src/setuptools_scm/file_finder_git.py
+++ b/src/setuptools_scm/file_finder_git.py
@@ -10,14 +10,21 @@ log = logging.getLogger(__name__)
def _git_toplevel(path):
+ from pathlib import Path
try:
+ cwd = os.path.abspath(path or ".")
with open(os.devnull, "wb") as devnull:
out = subprocess.check_output(
- ["git", "rev-parse", "--show-toplevel"],
- cwd=(path or "."),
+ ["git", "rev-parse", "--show-prefix"],
+ cwd=cwd,
universal_newlines=True,
stderr=devnull,
)
+ out = out.strip()
+ if not out:
+ out = cwd
+ else:
+ out = str(Path(cwd).parents[len(Path(out).parents) - 1])
trace("find files toplevel", out)
return os.path.normcase(os.path.realpath(out.strip()))
except subprocess.CalledProcessError:
diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py
index a193f93..e1b9f0a 100644
--- a/src/setuptools_scm/git.py
+++ b/src/setuptools_scm/git.py
@@ -26,9 +26,16 @@ class GitWorkdir(object):
@classmethod
def from_potential_worktree(cls, wd):
- real_wd, _, ret = do_ex("git rev-parse --show-toplevel", wd)
+ from pathlib import Path
+ import os
+ wd = os.path.abspath(wd)
+ real_wd, _, ret = do_ex("git rev-parse --show-prefix", wd)
if ret:
return
+ if not real_wd:
+ real_wd = wd
+ else:
+ real_wd = str(Path(wd).parents[len(Path(real_wd).parents) - 1])
trace("real root", real_wd)
if not samefile(real_wd, wd):
return
--
2.30.0