MCPcopy
hub / github.com/gitless-vcs/gitless / restore

Method restore

gitless/core.py:340–400  ·  view source on GitHub ↗
(b)

Source from the content-addressed store, hash-verified

338 git.stash.save('--all', '--', msg)
339
340 def restore(b):
341 s_id, msg = _stash(_stash_msg(b.branch_name))
342 if not s_id:
343 return
344
345 def restore_au_info():
346 au = au_fp(b)
347 if os.path.exists(au):
348 with io.open(au, mode='r', encoding=ENCODING) as f:
349 au_fps = f.read()
350 update_index('--assume-unchanged', au_fps)
351 os.remove(au)
352
353 split_msg = msg.split(INFO_SEP)
354
355 if len(split_msg) == 1: # No op to restore
356 # Pop
357 git.stash.pop(s_id)
358 # Restore assumed unchanged info
359 restore_au_info()
360 else: # Restore op
361 body = json.loads(split_msg[1])
362 # Restore ref info
363 ref_info = body[REF_INFO]
364 if 'GL_FUSE_ORIG_HEAD' in ref_info: # fuse
365 head = git_repo[ref_info['HEAD']]
366 git_repo.set_head(head.id)
367 git_repo.reset(head.id, pygit2.GIT_RESET_HARD)
368 self._ref_create('CHERRY_PICK_HEAD', ref_info['CHERRY_PICK_HEAD'])
369 self._ref_create('GL_FUSE_ORIG_HEAD', ref_info['GL_FUSE_ORIG_HEAD'])
370 else: # merge
371 self._ref_create('MERGE_HEAD', ref_info['MERGE_HEAD'])
372
373 # Pop
374 git.stash.pop(s_id)
375
376 # Restore conflict info
377 conf_info = body[CONF_INFO]
378 rm_sentinel = lambda path: '0 {0}\t{1}'.format('0' * 40, path)
379 build_entry = (
380 lambda e, num: '{mode:o} {id} {0}\t{path}'.format(num, **e))
381 index_info = []
382 for path, index_e in conf_info.items():
383 index_info.append(rm_sentinel(path))
384 if index_e[ANCESTOR]:
385 index_info.append(build_entry(index_e[ANCESTOR], 1))
386 if index_e[OURS]:
387 index_info.append(build_entry(index_e[OURS], 2))
388 if index_e[THEIRS]:
389 index_info.append(build_entry(index_e[THEIRS], 3))
390
391 update_index('--unresolve', _in=' '.join(conf_info.keys()))
392 update_index('--index-info', _in='\n'.join(index_info))
393
394 # Restore msg info
395 merge_msg_fp = os.path.join(self.path, 'MERGE_MSG')
396 with io.open(merge_msg_fp, 'w', encoding=ENCODING) as f:
397 f.write(body[MSG_INFO])

Callers

nothing calls this directly

Calls 3

_ref_createMethod · 0.95
_stashFunction · 0.85
_stash_msgFunction · 0.85

Tested by

no test coverage detected