From 8fa67dab95957e11fdb270d9ec19593a5ceda8a0 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Wed, 6 Dec 2017 16:27:11 +0000 Subject: [PATCH] stg rebase must delete stale files The old git.rebase() implementation uses 'git checkout-index' which does not delete the stale files after resetting the tree to a new tree_id. This patch changes the git.checkout() implementation to user 'git read-tree --reset -u' directly, together with some cleanup of the related function arguments. Signed-off-by: Catalin Marinas --- stgit/git.py | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/stgit/git.py b/stgit/git.py index b9b145b..6193956 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -670,22 +670,13 @@ def pretty_commit(commit_id = 'HEAD', flags = []): """ return GRun('show', *(flags + [commit_id])).raw_output() -def checkout(files = None, tree_id = None, force = False): - """Check out the given or all files +def checkout(tree_id): + """Check out the given tree_id """ - if tree_id: - try: - GRun('read-tree', '--reset', tree_id).run() - except GitRunException: - raise GitException('Failed "git read-tree" --reset %s' % tree_id) - - cmd = ['checkout-index', '-q', '-u'] - if force: - cmd.append('-f') - if files: - GRun(*(cmd + ['--'])).xargs(files) - else: - GRun(*(cmd + ['-a'])).run() + try: + GRun('read-tree', '--reset', '-u', tree_id).run() + except GitRunException: + raise GitException('Failed "git read-tree" --reset %s' % tree_id) def switch(tree_id, keep = False): """Switch the tree to the given id @@ -702,19 +693,15 @@ def switch(tree_id, keep = False): __set_head(tree_id) -def reset(files = None, tree_id = None, check_out = True): +def reset(tree_id = None): """Revert the tree changes relative to the given tree_id. It removes any local changes """ if not tree_id: tree_id = get_head() - if check_out: - checkout(files, tree_id, True) - - # if the reset refers to the whole tree, switch the HEAD as well - if not files: - __set_head(tree_id) + checkout(tree_id) + __set_head(tree_id) def fetch(repository = 'origin', refspec = None): @@ -766,7 +753,7 @@ def rebase(tree_id = None): Run(*(command.split() + args)).run() else: # default rebasing - reset(tree_id = tree_id) + reset(tree_id) def repack(): """Repack all objects into a single pack -- 2.11.4.GIT