From 7b601c9e979785f3521395a4f8b2abbe0b6408eb Mon Sep 17 00:00:00 2001 Message-Id: <7b601c9e979785f3521395a4f8b2abbe0b6408eb.1715196965.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 7 Nov 2007 22:12:24 +0000 Subject: [PATCH] Fix more commands to run correctly in subdirectories Organization: Straylight/Edgeware From: Catalin Marinas Raised recently with bug #10276, commands manipulating patches might fail to run correctly (even losing data) in subdirectories, mainly because of git-apply (see the bug log for explanation). This patch forces all the patch-modifying commands to go to the top level directory before acting. In addition to the above, ot also fixes the resolved and export commands. Signed-off-by: Catalin Marinas --- stgit/commands/assimilate.py | 2 +- stgit/commands/branch.py | 2 +- stgit/commands/clean.py | 2 +- stgit/commands/commit.py | 2 +- stgit/commands/delete.py | 2 +- stgit/commands/edit.py | 2 +- stgit/commands/export.py | 1 + stgit/commands/float.py | 2 +- stgit/commands/goto.py | 2 +- stgit/commands/new.py | 2 +- stgit/commands/pick.py | 2 +- stgit/commands/pop.py | 2 +- stgit/commands/pull.py | 2 +- stgit/commands/rebase.py | 2 +- stgit/commands/resolved.py | 3 +++ stgit/commands/sink.py | 2 +- stgit/commands/sync.py | 2 +- stgit/commands/uncommit.py | 2 +- 18 files changed, 20 insertions(+), 16 deletions(-) diff --git a/stgit/commands/assimilate.py b/stgit/commands/assimilate.py index db8a95c..be992aa 100644 --- a/stgit/commands/assimilate.py +++ b/stgit/commands/assimilate.py @@ -53,7 +53,7 @@ Note that these are "inconsistencies", not "errors"; furthermore, with the way "assimilate" handles them, you have no reason to avoid causing them in the first place if that is convenient for you.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [] class Commit(object): diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index a18ef2a..8723931 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -40,7 +40,7 @@ When displaying the branches, the names can be prefixed with If not given any options, switch to the named branch.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-c', '--create', help = 'create a new development branch', action = 'store_true'), diff --git a/stgit/commands/clean.py b/stgit/commands/clean.py index 4484ecd..c703418 100644 --- a/stgit/commands/clean.py +++ b/stgit/commands/clean.py @@ -31,7 +31,7 @@ Delete the empty patches in the whole series or only those applied or unapplied. A patch is considered empty if the two commit objects representing its boundaries refer to the same tree object.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-a', '--applied', help = 'delete the empty applied patches', action = 'store_true'), diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py index 23b4dc1..e56f5a0 100644 --- a/stgit/commands/commit.py +++ b/stgit/commands/commit.py @@ -32,7 +32,7 @@ remove them from the series while advancing the base. Use this command only if you want to permanently store the applied patches and no longer manage them with StGIT.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [] diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index fdb254e..1696cb9 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -36,7 +36,7 @@ patches are deleted, they are popped from the stack. Note that the 'delete' operation is irreversible.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-b', '--branch', help = 'use BRANCH instead of the default one')] diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py index 89d534a..a4d8f96 100644 --- a/stgit/commands/edit.py +++ b/stgit/commands/edit.py @@ -57,7 +57,7 @@ rejected patch is stored in the .stgit-failed.patch file (and also in these files using the '--file' and '--diff' options. """ -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-d', '--diff', help = 'edit the patch diff', action = 'store_true'), diff --git a/stgit/commands/export.py b/stgit/commands/export.py index d8ce86d..9131729 100644 --- a/stgit/commands/export.py +++ b/stgit/commands/export.py @@ -78,6 +78,7 @@ def func(parser, options, args): dirname = options.dir else: dirname = 'patches-%s' % crt_series.get_name() + directory.cd_to_topdir() if not options.branch and git.local_changes(): out.warn('Local changes in the tree;' diff --git a/stgit/commands/float.py b/stgit/commands/float.py index 6c07136..0ba4446 100644 --- a/stgit/commands/float.py +++ b/stgit/commands/float.py @@ -31,7 +31,7 @@ necessary pop and push operations will be performed to accomplish this. The '--series' option can be used to rearrange the (top) patches as specified by the given series file (or the standard input).""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-s', '--series', help = 'rearrange according to a series file', action = 'store_true')] diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py index e7aa588..7f9d45d 100644 --- a/stgit/commands/goto.py +++ b/stgit/commands/goto.py @@ -31,7 +31,7 @@ line becomes current. This is a shortcut for the 'push --to' or 'pop --to' commands. There is no '--undo' option for 'goto'. Use the 'push' command for this.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-k', '--keep', help = 'keep the local changes when popping patches', action = 'store_true')] diff --git a/stgit/commands/new.py b/stgit/commands/new.py index b0a57d1..49c729d 100644 --- a/stgit/commands/new.py +++ b/stgit/commands/new.py @@ -38,7 +38,7 @@ needed for this. If no name is given for the new patch, one is generated from the first line of the commit message.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-m', '--message', help = 'use MESSAGE as the patch description'), make_option('-s', '--showpatch', diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py index 1fcc2e2..5b45434 100644 --- a/stgit/commands/pick.py +++ b/stgit/commands/pick.py @@ -34,7 +34,7 @@ the name of the current patch. It can be overridden with the '--name' option. A commit object can be reverted with the '--reverse' option. The log and author information are those of the commit object.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-n', '--name', help = 'use NAME as the patch name'), make_option('-r', '--reverse', diff --git a/stgit/commands/pop.py b/stgit/commands/pop.py index 246cc34..dedf41b 100644 --- a/stgit/commands/pop.py +++ b/stgit/commands/pop.py @@ -36,7 +36,7 @@ patches passed on the command line are popped from the stack. Some of the push operations may fail because of conflicts (push --undo would revert the last push operation).""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-a', '--all', help = 'pop all the applied patches', action = 'store_true'), diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py index 0078e55..bec7fd7 100644 --- a/stgit/commands/pull.py +++ b/stgit/commands/pull.py @@ -38,7 +38,7 @@ resolved and the patch pushed again. Check the 'git fetch' documentation for the format.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-n', '--nopush', help = 'do not push the patches back after pulling', action = 'store_true'), diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py index c4d74b7..12faaf8 100644 --- a/stgit/commands/rebase.py +++ b/stgit/commands/rebase.py @@ -29,7 +29,7 @@ usage = """%prog [options] Pop all patches from current stack, move the stack base to the given and push the patches back.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-n', '--nopush', help = 'do not push the patches back after rebasing', action = 'store_true'), diff --git a/stgit/commands/resolved.py b/stgit/commands/resolved.py index c2ef678..236ffd7 100644 --- a/stgit/commands/resolved.py +++ b/stgit/commands/resolved.py @@ -47,6 +47,9 @@ options = [make_option('-a', '--all', def func(parser, options, args): """Mark the conflict as resolved """ + args = git.ls_files(args) + directory.cd_to_topdir() + if options.reset \ and options.reset not in file_extensions(): raise CmdException, 'Unknown reset state: %s' % options.reset diff --git a/stgit/commands/sink.py b/stgit/commands/sink.py index b177337..2167d87 100644 --- a/stgit/commands/sink.py +++ b/stgit/commands/sink.py @@ -32,7 +32,7 @@ push the specified (the current patch by default), and then push back into place the formerly-applied patches (unless -n is also given).""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-n', '--nopush', help = 'do not push the patches back after sinking', action = 'store_true'), diff --git a/stgit/commands/sync.py b/stgit/commands/sync.py index 6066f82..660ee41 100644 --- a/stgit/commands/sync.py +++ b/stgit/commands/sync.py @@ -36,7 +36,7 @@ in the series must apply cleanly. The sync operation can be reverted for individual patches with --undo.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-a', '--all', help = 'synchronise all the patches', action = 'store_true'), diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py index 8e62d23..9a46c94 100644 --- a/stgit/commands/uncommit.py +++ b/stgit/commands/uncommit.py @@ -48,7 +48,7 @@ given commit should be uncommitted. Only commits with exactly one parent can be uncommitted; in other words, you can't uncommit a merge.""" -directory = DirectoryHasRepository() +directory = DirectoryGotoToplevel() options = [make_option('-n', '--number', type = 'int', help = 'uncommit the specified number of commits'), make_option('-t', '--to', -- [mdw]