Skip to content

Commit 01e2975

Browse files
committed
improve handling of tag not found
1 parent cbf30d8 commit 01e2975

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

git_fleximod/submodule.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,26 @@ def status(self):
119119
atag = atag[:-1]
120120
if atag == self.fxtag:
121121
break
122-
123122

124-
#print(f"line is {line} ahash is {ahash} atag is {atag} {parts}")
125-
# atag = git.git_operation("describe", "--tags", "--always")
126-
# ahash = git.git_operation("rev-list", "HEAD").partition("\n")[0]
127-
128123
recurse = False
129124
if rurl != self.url:
130125
remote = self._add_remote(git)
131126
git.git_operation("fetch", remote)
127+
# Asked for a tag and found that tag
132128
if self.fxtag and atag == self.fxtag:
133129
result = f" {self.name:>20} at tag {self.fxtag}"
134130
recurse = True
135131
testfails = False
132+
# Asked for and found a hash
136133
elif self.fxtag and (ahash[: len(self.fxtag)] == self.fxtag or (self.fxtag.find(ahash)==0)):
137134
result = f" {self.name:>20} at hash {ahash}"
138135
recurse = True
139136
testfails = False
137+
# Asked for and found a hash
140138
elif atag == ahash:
141139
result = f" {self.name:>20} at hash {ahash}"
142140
recurse = True
141+
# Did not find requested tag or hash
143142
elif self.fxtag:
144143
result = f"s {self.name:>20} {atag} {ahash} is out of sync with .gitmodules {self.fxtag}"
145144
testfails = True
@@ -396,13 +395,19 @@ async def update(self):
396395
smgit = GitInterface(repodir, self.logger)
397396
newremote = self._add_remote(smgit)
398397
# Trying to distingush a tag from a hash
399-
allowed = set(string.digits + 'abcdef')
398+
allowed = set(string.digits + 'abcdef')
399+
status = 0
400400
if not set(self.fxtag) <= allowed:
401401
# This is a tag
402402
tag = f"refs/tags/{self.fxtag}:refs/tags/{self.fxtag}"
403-
smgit.git_operation("fetch", newremote, tag)
404-
smgit.git_operation("checkout", self.fxtag)
405-
403+
status,_ = smgit.git_operation("fetch", newremote, tag)
404+
if status == 0:
405+
status,_ = smgit.git_operation("checkout", self.fxtag)
406+
if status:
407+
utils.fatal_error(
408+
f"Failed to checkout {self.name} at tag or hash {self.fxtag} from {repodir}"
409+
)
410+
406411
if not os.path.exists(os.path.join(repodir, ".git")):
407412
utils.fatal_error(
408413
f"Failed to checkout {self.name} {repo_exists} {repodir} {self.path}"

tests/test_c_required.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import re
23
from pathlib import Path
34

45
def test_required(git_fleximod, test_repo, shared_repos):
@@ -28,3 +29,15 @@ def test_required(git_fleximod, test_repo, shared_repos):
2829
assert result.returncode == 0
2930
status = git_fleximod(test_repo, f"status {repo_name}")
3031
assert shared_repos["status4"] in status.stdout
32+
33+
text = file_path.read_text()
34+
new_value = "somethingelse"
35+
pattern = r"(^\s*fxtag\s*=\s*).*$"
36+
replacement = r"\1" + new_value
37+
new_text = re.sub(pattern, replacement, text, flags=re.MULTILINE)
38+
39+
# Write updated content back to file
40+
file_path.write_text(new_text)
41+
42+
result = git_fleximod(test_repo, f"update {repo_name}")
43+
assert f'fatal: couldn\'t find remote ref' in result.stderr or 'error: pathspec \'somethingelse\' did not match any file(s) known to git' in result.stderr

0 commit comments

Comments
 (0)