def rebase(target): if target == git.get_head(): out.info('Already at "%s", no need for rebasing.' % target) return out.start('Rebasing to "%s"' % target) git.reset(tree_id = git_id(target)) out.done()
def func(parser, options, args): """Show the tree status """ if options.reset: if args: for f in args: resolved(f) git.reset(args) else: resolved_all() git.reset() else: if options.diff_opts: diff_flags = options.diff_opts.split() else: diff_flags = [] git.status(args, options.modified, options.new, options.deleted, options.conflict, options.unknown, options.noexclude, diff_flags=diff_flags)
def merged_patches(self, names): """Test which patches were merged upstream by reverse-applying them in reverse order. The function returns the list of patches detected to have been applied. The state of the tree is restored to the original one """ patches = [self.get_patch(name) for name in names] patches.reverse() merged = [] for p in patches: if git.apply_diff(p.get_top(), p.get_bottom()): merged.append(p.get_name()) merged.reverse() git.reset() return merged
def func(parser, options, args): """Show the tree status """ args = git.ls_files(args) directory.cd_to_topdir() if options.reset: directory.log = True if args: conflicts = git.get_conflicts() git.resolved([fn for fn in args if fn in conflicts]) git.reset(args) else: resolved_all() git.reset() else: status(args, options.modified, options.new, options.deleted, options.conflict, options.unknown, options.noexclude)
def undo_refresh(self): """Undo the patch boundaries changes caused by 'refresh' """ name = self.get_current() assert (name) patch = Patch(name, self.__patch_dir, self.__refs_dir) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top() # the bottom of the patch is not changed by refresh. If the # old_bottom is different, there wasn't any previous 'refresh' # command (probably only a 'push') if old_bottom != patch.get_bottom() or old_top == patch.get_top(): raise StackException, 'No undo information available' git.reset(tree_id=old_top, check_out=False) if patch.restore_old_boundaries(): self.log_patch(patch, 'undo')
def undo_push(self): name = self.get_current() assert (name) patch = Patch(name, self.__patch_dir, self.__refs_dir) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top() # the top of the patch is changed by a push operation only # together with the bottom (otherwise the top was probably # modified by 'refresh'). If they are both unchanged, there # was a fast forward if old_bottom == patch.get_bottom() and old_top != patch.get_top(): raise StackException, 'No undo information available' git.reset() self.pop_patch(name) ret = patch.restore_old_boundaries() if ret: self.log_patch(patch, 'undo') return ret
def func(parser, options, args): """Synchronise a range of patches """ if options.undo: if options.ref_branch or options.series: raise CmdException, \ '--undo cannot be specified with --ref-branch or --series' __check_all() out.start('Undoing the sync of "%s"' % crt_series.get_current()) crt_series.undo_refresh() git.reset() out.done() return if options.ref_branch: remote_series = stack.Series(options.ref_branch) if options.ref_branch == crt_series.get_name(): raise CmdException, 'Cannot synchronise with the current branch' remote_patches = remote_series.get_applied() # the merge function merge_patch(patch, pname) merge_patch = lambda patch, pname: \ __branch_merge_patch(remote_series, pname) elif options.series: patchdir = os.path.dirname(options.series) remote_patches = [] f = file(options.series) for line in f: p = re.sub('#.*$', '', line).strip() if not p: continue remote_patches.append(p) f.close() # the merge function merge_patch(patch, pname) merge_patch = lambda patch, pname: \ __series_merge_patch(patch.get_bottom(), patchdir, pname) else: raise CmdException, 'No remote branch or series specified' applied = crt_series.get_applied() if options.all: patches = applied elif len(args) != 0: patches = parse_patches(args, applied, ordered = True) elif applied: patches = [crt_series.get_current()] else: parser.error('no patches applied') if not patches: raise CmdException, 'No patches to synchronise' __check_all() # only keep the patches to be synchronised sync_patches = [p for p in patches if p in remote_patches] if not sync_patches: raise CmdException, 'No common patches to be synchronised' # pop to the one before the first patch to be synchronised popped = applied[applied.index(sync_patches[0]) + 1:] if popped: pop_patches(popped[::-1]) for p in sync_patches: if p in popped: # push to this patch idx = popped.index(p) + 1 push_patches(popped[:idx]) del popped[:idx] # the actual sync out.start('Synchronising "%s"' % p) patch = crt_series.get_patch(p) bottom = patch.get_bottom() top = patch.get_top() # reset the patch backup information. That's needed in case we # undo the sync but there were no changes made patch.set_bottom(bottom, backup = True) patch.set_top(top, backup = True) # the actual merging (either from a branch or an external file) merge_patch(patch, p) if git.local_changes(verbose = False): # index (cache) already updated by the git merge. The # backup information was already reset above crt_series.refresh_patch(cache_update = False, backup = False, log = 'sync') out.done('updated') else: out.done() # push the remaining patches if popped: push_patches(popped)