| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -432,20 +432,47 @@ def _from_line(cls, repo, line, fetch_line): | |||
| 432 | 432 | ref_type = None | |
| 433 | 433 | if remote_local_ref == "FETCH_HEAD": | |
| 434 | 434 | ref_type = SymbolicReference | |
| 435 | - elif ref_type_name == "branch": | ||
| 435 | + elif ref_type_name in ("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 | ||
| 436 | 438 | ref_type = RemoteReference | |
| 437 | 439 | elif ref_type_name == "tag": | |
| 438 | 440 | ref_type = TagReference | |
| 439 | 441 | else: | |
| 440 | 442 | raise TypeError("Cannot handle reference type: %r" % ref_type_name) | |
| 443 | + #END handle ref type | ||
| 441 | 444 | ||
| 442 | 445 | # create ref instance | |
| 443 | 446 | if ref_type is SymbolicReference: | |
| 444 | 447 | remote_local_ref = ref_type(repo, "FETCH_HEAD") | |
| 445 | 448 | 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 | + if remote_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 | + if ref_type is not TagReference and not remote_local_ref.startswith(RemoteReference._common_path_default + "/"): | ||
| 461 | + ref_type = Reference | ||
| 462 | + #END downgrade remote reference | ||
| 463 | + elif ref_type is TagReference and 'tags/' in remote_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) | ||
| 447 | 473 | # END create ref instance | |
| 448 | 474 | ||
| 475 | + | ||
| 449 | 476 | note = ( note and note.strip() ) or '' | |
| 450 | 477 | ||
| 451 | 478 | # parse flags from control_character | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,8 @@ | |||
| 11 | 11 | from git.db.complex import CmdCompatibilityGitDB | |
| 12 | 12 | from git.db.cmd.base import * | |
| 13 | 13 | ||
| 14 | + from git.refs import TagReference, Reference, RemoteReference | ||
| 15 | + | ||
| 14 | 16 | class TestBase(RepoBase): | |
| 15 | 17 | RepoCls = CmdCompatibilityGitDB | |
| 16 | 18 | ||
@@ -28,5 +30,62 @@ def test_basics(self): | |||
| 28 | 30 | self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev) | |
| 29 | 31 | ||
| 30 | 32 | def test_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 | + def test_fetch_info(self): | ||
| 38 | + # assure we can handle remote-tracking branches | ||
| 39 | + fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-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 | + assert isinstance(fi.ref, TagReference) | ||
| 55 | + assert fi.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 | + assert isinstance(fi.ref, TagReference) | ||
| 63 | + assert fi.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 | + assert isinstance(fi.ref, TagReference) | ||
| 72 | + assert fi.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 | + assert isinstance(fi.ref, RemoteReference) | ||
| 80 | + assert fi.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 | + assert type(fi.ref) is Reference | ||
| 88 | + assert fi.ref.path == "refs/something/branch" | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -256,7 +256,7 @@ def get_info(res, remote, name): | |||
| 256 | 256 | shutil.rmtree(other_repo_dir) | |
| 257 | 257 | # END test and cleanup | |
| 258 | 258 | ||
| 259 | - def _test_push_and_pull(self,remote, rw_repo, remote_repo): | ||
| 259 | + def _verify_push_and_pull(self,remote, rw_repo, remote_repo): | ||
| 260 | 260 | # push our changes | |
| 261 | 261 | lhead = rw_repo.head | |
| 262 | 262 | lindex = rw_repo.index | |
@@ -407,7 +407,7 @@ def test_base(self, rw_repo, remote_repo): | |||
| 407 | 407 | # END for each rename ( back to prev_name ) | |
| 408 | 408 | ||
| 409 | 409 | # 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) | ||
| 411 | 411 | ||
| 412 | 412 | # FETCH TESTING | |
| 413 | 413 | # Only for remotes - local cases are the same or less complicated | |
| Back | FazBrowse Home | New Git URL |
0 commit comments