Fix more commands to run correctly in subdirectories
authorCatalin Marinas <catalin.marinas@gmail.com>
Wed, 7 Nov 2007 22:12:24 +0000 (22:12 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 7 Nov 2007 22:12:24 +0000 (22:12 +0000)
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 <catalin.marinas@gmail.com>
18 files changed:
stgit/commands/assimilate.py
stgit/commands/branch.py
stgit/commands/clean.py
stgit/commands/commit.py
stgit/commands/delete.py
stgit/commands/edit.py
stgit/commands/export.py
stgit/commands/float.py
stgit/commands/goto.py
stgit/commands/new.py
stgit/commands/pick.py
stgit/commands/pop.py
stgit/commands/pull.py
stgit/commands/rebase.py
stgit/commands/resolved.py
stgit/commands/sink.py
stgit/commands/sync.py
stgit/commands/uncommit.py

index db8a95c..be992aa 100644 (file)
@@ -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):
index a18ef2a..8723931 100644 (file)
@@ -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'),
index 4484ecd..c703418 100644 (file)
@@ -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'),
index 23b4dc1..e56f5a0 100644 (file)
@@ -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 = []
 
 
index fdb254e..1696cb9 100644 (file)
@@ -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')]
 
index 89d534a..a4d8f96 100644 (file)
@@ -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'),
index d8ce86d..9131729 100644 (file)
@@ -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;'
index 6c07136..0ba4446 100644 (file)
@@ -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')]
index e7aa588..7f9d45d 100644 (file)
@@ -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')]
index b0a57d1..49c729d 100644 (file)
@@ -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',
index 1fcc2e2..5b45434 100644 (file)
@@ -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',
index 246cc34..dedf41b 100644 (file)
@@ -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'),
index 0078e55..bec7fd7 100644 (file)
@@ -38,7 +38,7 @@ resolved and the patch pushed again.
 
 Check the 'git fetch' documentation for the <repository> format."""
 
-directory = DirectoryHasRepository()
+directory = DirectoryGotoToplevel()
 options = [make_option('-n', '--nopush',
                        help = 'do not push the patches back after pulling',
                        action = 'store_true'),
index c4d74b7..12faaf8 100644 (file)
@@ -29,7 +29,7 @@ usage = """%prog [options] <new-base-id>
 Pop all patches from current stack, move the stack base to the given
 <new-base-id> 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'),
index c2ef678..236ffd7 100644 (file)
@@ -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
index b177337..2167d87 100644 (file)
@@ -32,7 +32,7 @@ push the specified <patches> (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'),
index 6066f82..660ee41 100644 (file)
@@ -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'),
index 8e62d23..9a46c94 100644 (file)
@@ -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',