Fetch info can now deal much better with non-default ref specs, fixes… · gitpython-developers/GitPython@c555840 · GitHub
Skip to content

Commit c555840

Browse files
committed
Fetch info can now deal much better with non-default ref specs, fixes #24, #25
1 parent 916c45d commit c555840

4 files changed

Lines changed: 77 additions & 9 deletions

File tree

.gitmodules

Lines changed: 3 additions & 3 deletions

git/ext/gitdb

Submodule gitdb updated 1 file

git/remote.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,36 @@ def _from_line(cls, repo, line, fetch_line):
279279
ref_type = TagReference
280280
else:
281281
raise TypeError("Cannot handle reference type: %r" % ref_type_name)
282+
#END handle ref type
282283

283284
# create ref instance
284285
if ref_type is SymbolicReference:
285286
remote_local_ref = ref_type(repo, "FETCH_HEAD")
286287
else:
287-
remote_local_ref = Reference.from_path(repo, join_path(ref_type._common_path_default, remote_local_ref.strip()))
288+
# determine prefix. Tags are usually pulled into refs/tags, they may have subdirectories.
289+
# It is not clear sometimes where exactly the item is, unless we have an absolute path as indicated
290+
# by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
291+
# 'tags/' subdirectory in its path.
292+
# We don't want to test for actual existence, but try to figure everything out analytically.
293+
ref_path = None
294+
remote_local_ref = remote_local_ref.strip()
295+
if remote_local_ref.startswith(Reference._common_path_default + "/"):
296+
# always use actual type if we get absolute paths
297+
# Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
298+
ref_path = remote_local_ref
299+
if ref_type is not TagReference and not remote_local_ref.startswith(RemoteReference._common_path_default + "/"):
300+
ref_type = Reference
301+
#END downgrade remote reference
302+
elif ref_type is TagReference and 'tags/' in remote_local_ref:
303+
# even though its a tag, it is located in refs/remotes
304+
ref_path = join_path(RemoteReference._common_path_default, remote_local_ref)
305+
else:
306+
ref_path = join_path(ref_type._common_path_default, remote_local_ref)
307+
#END obtain refpath
308+
309+
# even though the path could be within the git conventions, we make
310+
# sure we respect whatever the user wanted, and disabled path checking
311+
remote_local_ref = ref_type(repo, ref_path, check_path=False)
288312
# END create ref instance
289313

290314
note = ( note and note.strip() ) or ''

git/test/test_remote.py

Lines changed: 48 additions & 4 deletions

0 commit comments

Comments
 (0)