Skip to content

Commit 517219a

Browse files
committed
tools/import-orig: support git < 2.46.0
1 parent 370c819 commit 517219a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tools/import-orig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ class ImportTool:
1616
self._package_version = args.package_version
1717
self._package_name = args.package_name
1818
self._package_ext = None
19+
self._git_version = None
20+
21+
def _determine_git_version(self):
22+
output = subprocess.check_output(["/usr/bin/git", "--version"])
23+
parts = output.split()
24+
if len(parts) != 3:
25+
print("ERROR: unexpected 'git --version' format", file=sys.stderr)
26+
return
27+
if parts[0] != "git" or parts[1] != "version":
28+
print("ERROR: unexpected 'git --version' format", file=sys.stderr)
29+
return
30+
major, minor, patch = parts[2].split(".")
31+
self._git_version = (int(major), int(minor), int(patch))
1932

2033
def _detect_package_details(self):
2134
# Compute filetype
@@ -76,8 +89,12 @@ class ImportTool:
7689
cwd=worktree,
7790
)
7891
return None
92+
93+
show_ref_flag = "--branches"
94+
if self._git_version < (2, 46, 0):
95+
show_ref_flag = "--heads"
7996
output = subprocess.check_output(
80-
["/usr/bin/git", "show-ref", "--branches", branch_name],
97+
["/usr/bin/git", "show-ref", show_ref_flag, branch_name],
8198
cwd=worktree,
8299
)
83100
return output.splitlines()[0].split(None, 1)[0]
@@ -206,6 +223,7 @@ class ImportTool:
206223
print("ERROR: non-existent source", file=sys.stderr)
207224
return
208225

226+
self._determine_git_version()
209227
self._detect_package_details()
210228

211229
print(

0 commit comments

Comments
 (0)