Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3379127

Browse files
committed
Fetch info can now deal much better with non-default ref specs, seegitpython-developers#23,gitpython-developers#24,gitpython-developers#25
1 parent87c7a6f commit3379127

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

‎git/db/cmd/base.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,47 @@ def _from_line(cls, repo, line, fetch_line):
432432
ref_type=None
433433
ifremote_local_ref=="FETCH_HEAD":
434434
ref_type=SymbolicReference
435-
elifref_type_name=="branch":
435+
elifref_type_namein ("remote-tracking","branch"):
436+
# note: remote-tracking is just the first part of the 'remote-tracking branch' token.
437+
# We don't parse it correctly, but its enough to know what to do, and its new in git 1.7something
436438
ref_type=RemoteReference
437439
elifref_type_name=="tag":
438440
ref_type=TagReference
439441
else:
440442
raiseTypeError("Cannot handle reference type: %r"%ref_type_name)
443+
#END handle ref type
441444

442445
# create ref instance
443446
ifref_typeisSymbolicReference:
444447
remote_local_ref=ref_type(repo,"FETCH_HEAD")
445448
else:
446-
remote_local_ref=Reference.from_path(repo,join_path(ref_type._common_path_default,remote_local_ref.strip()))
449+
# determine prefix. Tags are usually pulled into refs/tags, they may have subdirectories.
450+
# It is not clear sometimes where exactly the item is, unless we have an absolute path as indicated
451+
# by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
452+
# 'tags/' subdirectory in its path.
453+
# We don't want to test for actual existence, but try to figure everything out analytically.
454+
ref_path=None
455+
remote_local_ref=remote_local_ref.strip()
456+
ifremote_local_ref.startswith(Reference._common_path_default+"/"):
457+
# always use actual type if we get absolute paths
458+
# Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
459+
ref_path=remote_local_ref
460+
ifref_typeisnotTagReferenceandnotremote_local_ref.startswith(RemoteReference._common_path_default+"/"):
461+
ref_type=Reference
462+
#END downgrade remote reference
463+
elifref_typeisTagReferenceand'tags/'inremote_local_ref:
464+
# even though its a tag, it is located in refs/remotes
465+
ref_path=join_path(RemoteReference._common_path_default,remote_local_ref)
466+
else:
467+
ref_path=join_path(ref_type._common_path_default,remote_local_ref)
468+
#END obtain refpath
469+
470+
# even though the path could be within the git conventions, we make
471+
# sure we respect whatever the user wanted, and disabled path checking
472+
remote_local_ref=ref_type(repo,ref_path,check_path=False)
447473
# END create ref instance
448474

475+
449476
note= (noteandnote.strip() )or''
450477

451478
# parse flags from control_character

‎git/test/db/cmd/test_base.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
fromgit.db.compleximportCmdCompatibilityGitDB
1212
fromgit.db.cmd.baseimport*
1313

14+
fromgit.refsimportTagReference,Reference,RemoteReference
15+
1416
classTestBase(RepoBase):
1517
RepoCls=CmdCompatibilityGitDB
1618

@@ -28,5 +30,62 @@ def test_basics(self):
2830
self.failUnlessRaises(BadObject,gdb.partial_to_complete_sha_hex,invalid_rev)
2931

3032
deftest_fetch_info(self):
31-
self.failUnlessRaises(ValueError,CmdFetchInfo._from_line,self.rorepo,"nonsense",'')
32-
self.failUnlessRaises(ValueError,CmdFetchInfo._from_line,self.rorepo,"? [up to date] 0.1.7RC -> origin/0.1.7RC",'')
33+
self.failUnlessRaises(ValueError,CmdCmdFetchInfo._from_line,self.rorepo,"nonsense",'')
34+
self.failUnlessRaises(ValueError,CmdCmdFetchInfo._from_line,self.rorepo,"? [up to date] 0.1.7RC -> origin/0.1.7RC",'')
35+
36+
37+
deftest_fetch_info(self):
38+
# assure we can handle remote-tracking branches
39+
fetch_info_line_fmt="c437ee5deb8d00cf02f03720693e4c802e99f390not-for-merge%s '0.3' of git://github.com/gitpython-developers/GitPython"
40+
remote_info_line_fmt="* [new branch] nomatter -> %s"
41+
fi=CmdFetchInfo._from_line(self.rorepo,
42+
remote_info_line_fmt%"local/master",
43+
fetch_info_line_fmt%'remote-tracking branch')
44+
45+
# we wouldn't be here if it wouldn't have worked
46+
47+
# handles non-default refspecs: One can specify a different path in refs/remotes
48+
# or a special path just in refs/something for instance
49+
50+
fi=CmdFetchInfo._from_line(self.rorepo,
51+
remote_info_line_fmt%"subdir/tagname",
52+
fetch_info_line_fmt%'tag')
53+
54+
assertisinstance(fi.ref,TagReference)
55+
assertfi.ref.path.startswith('refs/tags')
56+
57+
# it could be in a remote direcftory though
58+
fi=CmdFetchInfo._from_line(self.rorepo,
59+
remote_info_line_fmt%"remotename/tags/tagname",
60+
fetch_info_line_fmt%'tag')
61+
62+
assertisinstance(fi.ref,TagReference)
63+
assertfi.ref.path.startswith('refs/remotes/')
64+
65+
# it can also be anywhere !
66+
tag_path="refs/something/remotename/tags/tagname"
67+
fi=CmdFetchInfo._from_line(self.rorepo,
68+
remote_info_line_fmt%tag_path,
69+
fetch_info_line_fmt%'tag')
70+
71+
assertisinstance(fi.ref,TagReference)
72+
assertfi.ref.path==tag_path
73+
74+
# branches default to refs/remotes
75+
fi=CmdFetchInfo._from_line(self.rorepo,
76+
remote_info_line_fmt%"remotename/branch",
77+
fetch_info_line_fmt%'branch')
78+
79+
assertisinstance(fi.ref,RemoteReference)
80+
assertfi.ref.remote_name=='remotename'
81+
82+
# but you can force it anywhere, in which case we only have a references
83+
fi=CmdFetchInfo._from_line(self.rorepo,
84+
remote_info_line_fmt%"refs/something/branch",
85+
fetch_info_line_fmt%'branch')
86+
87+
asserttype(fi.ref)isReference
88+
assertfi.ref.path=="refs/something/branch"
89+
90+
91+

‎git/test/test_remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def get_info(res, remote, name):
256256
shutil.rmtree(other_repo_dir)
257257
# END test and cleanup
258258

259-
def_test_push_and_pull(self,remote,rw_repo,remote_repo):
259+
def_verify_push_and_pull(self,remote,rw_repo,remote_repo):
260260
# push our changes
261261
lhead=rw_repo.head
262262
lindex=rw_repo.index
@@ -407,7 +407,7 @@ def test_base(self, rw_repo, remote_repo):
407407
# END for each rename ( back to prev_name )
408408

409409
# PUSH/PULL TESTING
410-
self._test_push_and_pull(remote,rw_repo,remote_repo)
410+
self._verify_push_and_pull(remote,rw_repo,remote_repo)
411411

412412
# FETCH TESTING
413413
# Only for remotes - local cases are the same or less complicated

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp