From: Catalin Marinas Date: Mon, 8 May 2006 20:21:22 +0000 (+0100) Subject: Fix git.reset() to remove the added files X-Git-Tag: v0.14.3~498 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/9cfad9525f37ffe57edefe112982c46187a02ff6 Fix git.reset() to remove the added files The combination of git-read-tree and git-checkout-index used in the git.checkout() function doesn't remove the files added to the index. This patch adds the file removal support to the git.reset() function. It also changes the git.apply_diff() call in stack.Series.merged_patches() so that the the index is always updated (otherwise the reset wouldn't know which files to remove). Signed-off-by: Catalin Marinas --- diff --git a/stgit/git.py b/stgit/git.py index 6b14a74..2884f36 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -612,8 +612,8 @@ def checkout(files = None, tree_id = None, force = False): if not files: files = [] - if tree_id and __run('git-read-tree', [tree_id]) != 0: - raise GitException, 'Failed git-read-tree -m %s' % tree_id + if tree_id and __run('git-read-tree --reset', [tree_id]) != 0: + raise GitException, 'Failed git-read-tree --reset %s' % tree_id checkout_cmd = 'git-checkout-index -q -u' if force: @@ -643,7 +643,13 @@ def reset(files = None, tree_id = None, check_out = True): tree_id = get_head() if check_out: + cache_files = __tree_status(files, tree_id) + # files which were added but need to be removed + rm_files = [x[1] for x in cache_files if x[0] in ['A']] + checkout(files, tree_id, True) + # checkout doesn't remove files + map(os.remove, rm_files) # if the reset refers to the whole tree, switch the HEAD as well if not files: diff --git a/stgit/stack.py b/stgit/stack.py index 975ac21..f83161b 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -818,7 +818,7 @@ class Series: merged = [] for p in patches: - if git.apply_diff(p.get_top(), p.get_bottom(), False): + if git.apply_diff(p.get_top(), p.get_bottom()): merged.append(p.get_name()) merged.reverse()