Switches to the given branch. Args: dst_b: the destination branch. move_over: if True, then uncommitted changes made in the current branch are moved to the destination branch (defaults to False).
(self, dst_b, move_over=False)
| 246 | return self.git_repo.listall_branches(pygit2.GIT_BRANCH_LOCAL) |
| 247 | |
| 248 | def switch_current_branch(self, dst_b, move_over=False): |
| 249 | """Switches to the given branch. |
| 250 | |
| 251 | Args: |
| 252 | dst_b: the destination branch. |
| 253 | move_over: if True, then uncommitted changes made in the current branch are |
| 254 | moved to the destination branch (defaults to False). |
| 255 | """ |
| 256 | if dst_b.is_current: |
| 257 | raise ValueError( |
| 258 | 'You are already on branch {0}. No need to switch.'.format( |
| 259 | dst_b.branch_name)) |
| 260 | |
| 261 | INFO_SEP = '|' |
| 262 | ANCESTOR = 'ancestor' |
| 263 | THEIRS = 'theirs' |
| 264 | OURS = 'ours' |
| 265 | REF_INFO = 'ref_info' |
| 266 | CONF_INFO = 'conf_info' |
| 267 | MSG_INFO = 'msg_info' |
| 268 | |
| 269 | git_repo = self.git_repo |
| 270 | au_fp = lambda b: os.path.join( |
| 271 | self.path, 'GL_AU_{0}'.format(b.branch_name.replace('/', '_'))) |
| 272 | update_index = git.bake('update-index', _cwd=self.root) |
| 273 | |
| 274 | def save(b): |
| 275 | msg = _stash_msg(b.branch_name) |
| 276 | |
| 277 | # Save assumed unchanged info |
| 278 | au_fps = ' '.join(b._au_files()) |
| 279 | if au_fps: |
| 280 | with io.open(au_fp(b), mode='w', encoding=ENCODING) as f: |
| 281 | f.write(au_fps) |
| 282 | update_index('--no-assume-unchanged', au_fps) |
| 283 | |
| 284 | if b.merge_in_progress or b.fuse_in_progress: |
| 285 | body = {} |
| 286 | if move_over: |
| 287 | raise GlError( |
| 288 | 'Changes can\'t be moved over with a fuse or merge in progress') |
| 289 | |
| 290 | # Save msg info |
| 291 | merge_msg_fp = os.path.join(self.path, 'MERGE_MSG') |
| 292 | with io.open(merge_msg_fp, 'r', encoding=ENCODING) as f: |
| 293 | merge_msg = f.read() |
| 294 | os.remove(merge_msg_fp) |
| 295 | body[MSG_INFO] = merge_msg |
| 296 | |
| 297 | # Save conflict info |
| 298 | conf_info = {} |
| 299 | index = git_repo.index |
| 300 | index.read() |
| 301 | if index.conflicts: |
| 302 | extract = lambda e: {'mode': e.mode, 'id': str(e.id), 'path': e.path} |
| 303 | for ancestor, ours, theirs in index.conflicts: |
| 304 | if ancestor: |
| 305 | path = ancestor.path |