| 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 |
| 306 | ancestor = extract(ancestor) |
| 307 | if theirs: |
| 308 | path = theirs.path |
| 309 | theirs = extract(theirs) |
| 310 | if ours: |
| 311 | path = ours.path |
| 312 | ours = extract(ours) |
| 313 | |
| 314 | conf_info[path] = {ANCESTOR: ancestor, THEIRS: theirs, OURS: ours} |
| 315 | index.add(path) |
| 316 | |
| 317 | index.write() |
| 318 | body[CONF_INFO] = conf_info |
| 319 | |
| 320 | # Save ref info |
| 321 | if b.merge_in_progress: |
| 322 | ref_info = {'MERGE_HEAD': str(self._ref_target('MERGE_HEAD'))} |
| 323 | self._ref_rm('MERGE_HEAD') |
| 324 | else: |
| 325 | ref_info = { |
| 326 | 'HEAD': str(git_repo.head.target), |
| 327 | 'GL_FUSE_ORIG_HEAD': str(self._ref_target('GL_FUSE_ORIG_HEAD')), |
| 328 | 'CHERRY_PICK_HEAD': str(self._ref_target('CHERRY_PICK_HEAD')) |
| 329 | } |
| 330 | self._ref_rm('GL_FUSE_ORIG_HEAD') |
| 331 | self._ref_rm('CHERRY_PICK_HEAD') |