Skip to content

Commit c612d3d

Browse files
committed
Don't depend on a particular branch name when fetching tests
1 parent e3eb03b commit c612d3d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,24 @@ def fetch_git(self, url: str, location: str, commit_hash: str) -> None:
118118
repo = git.Repo(path)
119119

120120
print(f"Checking out the correct commit {commit_hash}...")
121-
branch = repo.heads["develop"]
122121
# Try to checkout the relevant commit hash and if that fails
123122
# fetch the latest changes and checkout the commit hash
123+
last_exception = None
124124
try:
125125
repo.git.checkout(commit_hash)
126-
except GitCommandError:
127-
repo.remotes.origin.fetch(branch.name)
128-
repo.git.checkout(commit_hash)
126+
except GitCommandError as e:
127+
last_exception = e
128+
for head in repo.heads:
129+
repo.remotes.origin.fetch(head.name)
130+
try:
131+
repo.git.checkout(commit_hash)
132+
last_exception = None
133+
break
134+
except GitCommandError as e:
135+
last_exception = e
136+
137+
if last_exception:
138+
raise last_exception
129139

130140
# Check if the submodule head matches the parent commit
131141
# If not, update the submodule

0 commit comments

Comments
 (0)