pull changes for the specified remote (defaults to origin). Code from MichaelBoselowitz at: https://github.com/MichaelBoselowitz/pygit2-examples/blob/ 68e889e50a592d30ab4105a2e7b9f28fac7324c8/examples.py#L58 licensed under the MIT license.
(self, repo, remote_name='origin', branch='master')
| 180 | AppLog.info('clone thread started') |
| 181 | |
| 182 | def pull(self, repo, remote_name='origin', branch='master'): |
| 183 | """ pull changes for the specified remote (defaults to origin). |
| 184 | |
| 185 | Code from MichaelBoselowitz at: |
| 186 | https://github.com/MichaelBoselowitz/pygit2-examples/blob/ |
| 187 | 68e889e50a592d30ab4105a2e7b9f28fac7324c8/examples.py#L58 |
| 188 | licensed under the MIT license. |
| 189 | """ |
| 190 | for remote in repo.remotes: |
| 191 | if remote.name == remote_name: |
| 192 | remote.fetch() |
| 193 | remote_master_id = repo.lookup_reference( |
| 194 | 'refs/remotes/origin/%s' % (branch)).target |
| 195 | merge_result, _ = repo.merge_analysis(remote_master_id) |
| 196 | # Up to date, do nothing |
| 197 | if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE: |
| 198 | return |
| 199 | # We can just fastforward |
| 200 | elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD: |
| 201 | repo.checkout_tree(repo.get(remote_master_id)) |
| 202 | try: |
| 203 | master_ref = repo.lookup_reference('refs/heads/%s' % |
| 204 | (branch)) |
| 205 | master_ref.set_target(remote_master_id) |
| 206 | except KeyError: |
| 207 | repo.create_branch(branch, repo.get(remote_master_id)) |
| 208 | repo.head.set_target(remote_master_id) |
| 209 | elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: |
| 210 | repo.merge(remote_master_id) |
| 211 | |
| 212 | if repo.index.conflicts is not None: |
| 213 | for conflict in repo.index.conflicts: |
| 214 | print('Conflicts found in:', conflict[0].path) |
| 215 | raise AssertionError('Conflicts, ahhhhh!!') |
| 216 | |
| 217 | user = repo.default_signature |
| 218 | tree = repo.index.write_tree() |
| 219 | repo.create_commit('HEAD', user, user, 'Merge!', tree, |
| 220 | [repo.head.target, remote_master_id]) |
| 221 | # We need to do this or git CLI will think we are still |
| 222 | # merging. |
| 223 | repo.state_cleanup() |
| 224 | else: |
| 225 | raise AssertionError('Unknown merge analysis result') |
| 226 | |
| 227 | def remove(self): |
| 228 | """删除未clone完成的目录""" |