| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 29c20c1 commit 2f8e6f7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | from git.utils import LazyMixin, Iterable, IterableList | |
| 11 | 11 | from objects import Commit | |
| 12 | - from refs import Reference, RemoteReference | ||
| 12 | + from refs import Reference, RemoteReference, SymbolicReference, TagReference | ||
| 13 | 13 | import re | |
| 14 | 14 | import os | |
| 15 | 15 | ||
@@ -57,13 +57,16 @@ class FetchInfo(object): | |||
| 57 | 57 | Carries information about the results of a fetch operation:: | |
| 58 | 58 | ||
| 59 | 59 | info = remote.fetch()[0] | |
| 60 | - info.remote_ref # Symbolic Reference or RemoteReference to the changed remote head or FETCH_HEAD | ||
| 61 | - info.flags # additional flags to be & with enumeration members, i.e. info.flags & info.REJECTED | ||
| 60 | + info.ref # Symbolic Reference or RemoteReference to the changed | ||
| 61 | + # remote head or FETCH_HEAD | ||
| 62 | + info.flags # additional flags to be & with enumeration members, | ||
| 63 | + # i.e. info.flags & info.REJECTED | ||
| 64 | + # is 0 if ref is SymbolicReference | ||
| 62 | 65 | info.note # additional notes given by git-fetch intended for the user | |
| 63 | - info.commit_before_forced_update # if info.flags & info.FORCED_UPDATE, field is set to the | ||
| 64 | - # previous location of remote_ref, otherwise None | ||
| 66 | + info.commit_before_forced_update # if info.flags & info.FORCED_UPDATE, | ||
| 67 | + # field is set to the previous location of ref, otherwise None | ||
| 65 | 68 | """ | |
| 66 | - __slots__ = ('remote_ref','commit_before_forced_update', 'flags', 'note') | ||
| 69 | + __slots__ = ('ref','commit_before_forced_update', 'flags', 'note') | ||
| 67 | 70 | ||
| 68 | 71 | BRANCH_UPTODATE, REJECTED, FORCED_UPDATE, FAST_FORWARD, NEW_TAG, \ | |
| 69 | 72 | TAG_UPDATE, NEW_BRANCH, ERROR = [ 1 << x for x in range(1,9) ] | |
@@ -73,11 +76,11 @@ class FetchInfo(object): | |||
| 73 | 76 | _flag_map = { '!' : ERROR, '+' : FORCED_UPDATE, '-' : TAG_UPDATE, '*' : 0, | |
| 74 | 77 | '=' : BRANCH_UPTODATE, ' ' : FAST_FORWARD } | |
| 75 | 78 | ||
| 76 | - def __init__(self, remote_ref, flags, note = '', old_commit = None): | ||
| 79 | + def __init__(self, ref, flags, note = '', old_commit = None): | ||
| 77 | 80 | """ | |
| 78 | 81 | Initialize a new instance | |
| 79 | 82 | """ | |
| 80 | - self.remote_ref = remote_ref | ||
| 83 | + self.ref = ref | ||
| 81 | 84 | self.flags = flags | |
| 82 | 85 | self.note = note | |
| 83 | 86 | self.commit_before_forced_update = old_commit | |
@@ -91,10 +94,10 @@ def name(self): | |||
| 91 | 94 | Returns | |
| 92 | 95 | Name of our remote ref | |
| 93 | 96 | """ | |
| 94 | - return self.remote_ref.name | ||
| 97 | + return self.ref.name | ||
| 95 | 98 | ||
| 96 | 99 | @classmethod | |
| 97 | - def _from_line(cls, repo, line): | ||
| 100 | + def _from_line(cls, repo, line, fetch_line): | ||
| 98 | 101 | """ | |
| 99 | 102 | Parse information from the given line as returned by git-fetch -v | |
| 100 | 103 | and return a new FetchInfo object representing this information. | |
@@ -109,13 +112,43 @@ def _from_line(cls, repo, line): | |||
| 109 | 112 | * means birth of new branch or tag | |
| 110 | 113 | = means the head was up to date ( and not moved ) | |
| 111 | 114 | ' ' means a fast-forward | |
| 115 | + | ||
| 116 | + fetch line is the corresponding line from FETCH_HEAD, like | ||
| 117 | + acb0fa8b94ef421ad60c8507b634759a472cd56c not-for-merge branch '0.1.7RC' of /tmp/tmpya0vairemote_repo | ||
| 112 | 118 | """ | |
| 113 | 119 | match = cls.re_fetch_result.match(line) | |
| 114 | 120 | if match is None: | |
| 115 | 121 | raise ValueError("Failed to parse line: %r" % line) | |
| 122 | + | ||
| 123 | + # parse lines | ||
| 116 | 124 | control_character, operation, local_remote_ref, remote_local_ref, note = match.groups() | |
| 125 | + try: | ||
| 126 | + new_hex_sha, fetch_operation, fetch_note = fetch_line.split("\t") | ||
| 127 | + ref_type_name, fetch_note = fetch_note.split(' ', 1) | ||
| 128 | + except ValueError: # unpack error | ||
| 129 | + raise ValueError("Failed to parse FETCH__HEAD line: %r" % fetch_line) | ||
| 130 | + | ||
| 131 | + # handle FETCH_HEAD and figure out ref type | ||
| 132 | + # If we do not specify a target branch like master:refs/remotes/origin/master, | ||
| 133 | + # the fetch result is stored in FETCH_HEAD which destroys the rule we usually | ||
| 134 | + # have. In that case we use a symbolic reference which is detached | ||
| 135 | + ref_type = None | ||
| 136 | + if remote_local_ref == "FETCH_HEAD": | ||
| 137 | + ref_type = SymbolicReference | ||
| 138 | + elif ref_type_name == "branch": | ||
| 139 | + ref_type = RemoteReference | ||
| 140 | + elif ref_type_name == "tag": | ||
| 141 | + ref_type = TagReference | ||
| 142 | + else: | ||
| 143 | + raise TypeError("Cannot handle reference type: %r" % ref_type_name) | ||
| 144 | + | ||
| 145 | + # create ref instance | ||
| 146 | + if ref_type is SymbolicReference: | ||
| 147 | + remote_local_ref = ref_type(repo, "FETCH_HEAD") | ||
| 148 | + else: | ||
| 149 | + remote_local_ref = Reference.from_path(repo, os.path.join(ref_type._common_path_default, remote_local_ref.strip())) | ||
| 150 | + # END create ref instance | ||
| 117 | 151 | ||
| 118 | - remote_local_ref = Reference.from_path(repo, os.path.join(RemoteReference._common_path_default, remote_local_ref.strip())) | ||
| 119 | 152 | note = ( note and note.strip() ) or '' | |
| 120 | 153 | ||
| 121 | 154 | # parse flags from control_character | |
@@ -126,17 +159,19 @@ def _from_line(cls, repo, line): | |||
| 126 | 159 | raise ValueError("Control character %r unknown as parsed from line %r" % (control_character, line)) | |
| 127 | 160 | # END control char exception hanlding | |
| 128 | 161 | ||
| 129 | - # parse operation string for more info | ||
| 162 | + # parse operation string for more info - makes no sense for symbolic refs | ||
| 130 | 163 | old_commit = None | |
| 131 | - if 'rejected' in operation: | ||
| 132 | - flags |= cls.REJECTED | ||
| 133 | - if 'new tag' in operation: | ||
| 134 | - flags |= cls.NEW_TAG | ||
| 135 | - if 'new branch' in operation: | ||
| 136 | - flags |= cls.NEW_BRANCH | ||
| 137 | - if '...' in operation: | ||
| 138 | - old_commit = Commit(repo, operation.split('...')[0]) | ||
| 139 | - # END handle refspec | ||
| 164 | + if isinstance(remote_local_ref, Reference): | ||
| 165 | + if 'rejected' in operation: | ||
| 166 | + flags |= cls.REJECTED | ||
| 167 | + if 'new tag' in operation: | ||
| 168 | + flags |= cls.NEW_TAG | ||
| 169 | + if 'new branch' in operation: | ||
| 170 | + flags |= cls.NEW_BRANCH | ||
| 171 | + if '...' in operation: | ||
| 172 | + old_commit = Commit(repo, operation.split('...')[0]) | ||
| 173 | + # END handle refspec | ||
| 174 | + # END reference flag handling | ||
| 140 | 175 | ||
| 141 | 176 | return cls(remote_local_ref, flags, note, old_commit) | |
| 142 | 177 | ||
@@ -316,7 +351,15 @@ def _get_fetch_info_from_stderr(self, stderr): | |||
| 316 | 351 | # skip first line as it is some remote info we are not interested in | |
| 317 | 352 | print stderr | |
| 318 | 353 | output = IterableList('name') | |
| 319 | - output.extend(self.FetchInfo._from_line(self.repo, line) for line in stderr.splitlines()[1:]) | ||
| 354 | + err_info = stderr.splitlines()[1:] | ||
| 355 | + | ||
| 356 | + # read head information | ||
| 357 | + fp = open(os.path.join(self.repo.path, 'FETCH_HEAD'),'r') | ||
| 358 | + fetch_head_info = fp.readlines() | ||
| 359 | + fp.close() | ||
| 360 | + | ||
| 361 | + output.extend(self.FetchInfo._from_line(self.repo, err_line, fetch_line) | ||
| 362 | + for err_line,fetch_line in zip(err_info, fetch_head_info)) | ||
| 320 | 363 | return output | |
| 321 | 364 | ||
| 322 | 365 | def fetch(self, refspec=None, **kwargs): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,11 +18,13 @@ def _print_fetchhead(self, repo): | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | def _test_fetch_result(self, results, remote): | |
| 21 | - self._print_fetchhead(remote.repo) | ||
| 21 | + # self._print_fetchhead(remote.repo) | ||
| 22 | 22 | assert len(results) > 0 and isinstance(results[0], remote.FetchInfo) | |
| 23 | 23 | for info in results: | |
| 24 | - assert info.flags != 0 | ||
| 25 | - assert isinstance(info.remote_ref, (SymbolicReference, Reference)) | ||
| 24 | + if isinstance(info.ref, Reference): | ||
| 25 | + assert info.flags != 0 | ||
| 26 | + # END referebce type flags handling | ||
| 27 | + assert isinstance(info.ref, (SymbolicReference, Reference)) | ||
| 26 | 28 | if info.flags & info.FORCED_UPDATE: | |
| 27 | 29 | assert isinstance(info.commit_before_forced_update, Commit) | |
| 28 | 30 | else: | |
@@ -31,8 +33,8 @@ def _test_fetch_result(self, results, remote): | |||
| 31 | 33 | # END for each info | |
| 32 | 34 | ||
| 33 | 35 | def _test_fetch_info(self, repo): | |
| 34 | - self.failUnlessRaises(ValueError, Remote.FetchInfo._from_line, repo, "nonsense") | ||
| 35 | - self.failUnlessRaises(ValueError, Remote.FetchInfo._from_line, repo, "? [up to date] 0.1.7RC -> origin/0.1.7RC") | ||
| 36 | + self.failUnlessRaises(ValueError, Remote.FetchInfo._from_line, repo, "nonsense", '') | ||
| 37 | + self.failUnlessRaises(ValueError, Remote.FetchInfo._from_line, repo, "? [up to date] 0.1.7RC -> origin/0.1.7RC", '') | ||
| 36 | 38 | ||
| 37 | 39 | def _test_fetch(self,remote, rw_repo, remote_repo): | |
| 38 | 40 | # specialized fetch testing to de-clutter the main test | |
@@ -80,7 +82,7 @@ def get_info(res, remote, name): | |||
| 80 | 82 | new_remote_branch.rename("other_branch_name") | |
| 81 | 83 | res = fetch_and_test(remote) | |
| 82 | 84 | other_branch_info = get_info(res, remote, new_remote_branch) | |
| 83 | - assert other_branch_info.remote_ref.commit == new_branch_info.remote_ref.commit | ||
| 85 | + assert other_branch_info.ref.commit == new_branch_info.ref.commit | ||
| 84 | 86 | ||
| 85 | 87 | # remove new branch | |
| 86 | 88 | Head.delete(new_remote_branch.repo, new_remote_branch) | |
@@ -93,19 +95,19 @@ def get_info(res, remote, name): | |||
| 93 | 95 | assert len(stale_refs) == 2 and isinstance(stale_refs[0], RemoteReference) | |
| 94 | 96 | RemoteReference.delete(rw_repo, *stale_refs) | |
| 95 | 97 | ||
| 96 | - # test single branch fetch with refspec | ||
| 98 | + # test single branch fetch with refspec including target remote | ||
| 97 | 99 | res = fetch_and_test(remote, refspec="master:refs/remotes/%s/master"%remote) | |
| 98 | 100 | assert len(res) == 1 and get_info(res, remote, 'master') | |
| 99 | 101 | ||
| 100 | - # without refspec | ||
| 102 | + # ... with respec and no target | ||
| 101 | 103 | res = fetch_and_test(remote, refspec='master') | |
| 102 | 104 | assert len(res) == 1 | |
| 103 | 105 | ||
| 104 | 106 | # add new tag reference | |
| 105 | 107 | rtag = TagReference.create(remote_repo, "1.0-RV_hello.there") | |
| 106 | 108 | res = fetch_and_test(remote, tags=True) | |
| 107 | 109 | ltag = res[str(rtag)] | |
| 108 | - assert isinstance(ltag, TagReference) | ||
| 110 | + assert isinstance(ltag.ref, TagReference) | ||
| 109 | 111 | ||
| 110 | 112 | # delete tag | |
| 111 | 113 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments