chiark / gitweb /
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 db8a95cdb7ae9850d98fcd81ad2206ec835c9f84..be992aaa25d61efb8cf819735a3250bff519d0e1 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 a18ef2ac34960002fdca622c2d0d17098466aa27..87239315ec776106f4c45f724959699b521f4b37 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 4484ecd53624c13e9929d601c59a8ed7b49dc04f..c703418df57e781db0247ccfa603b32e3b3dd80c 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 23b4dc11580617e10e1b1539416dc4bc6cbfe22f..e56f5a056d9c0d3b313aa59edd48d2906d48179d 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 fdb254ec18763e9ebcfc000303c8d72a5ac59f25..1696cb9c5497efae8a0a51955f4b5226147cd916 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 89d534a9971d4ec7a56af53beda41942d983c16a..a4d8f963f2a288169ecb326a1f4b6f899c32fac3 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 d8ce86d9f1604fe0c297080970b7b7ebfd189308..913172914feff00911a3415c1c1e6f1b5ab4c6d5 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 6c07136b0fa6aa9f210ee88b7269316d1312bb9d..0ba4446645a79aa722afc00a3940c7c3f70e613d 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 e7aa588bb1c637e5eb1d322ef16d136dc3ba2473..7f9d45da1d137b5b655c8b967c0f5ef7e3cb9ad6 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 b0a57d1579557bce6005191db84ad617a4bb5884..49c729d5e5c4412185c109da206deeeba15807cb 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 1fcc2e226fa55225992112632b037fd531fc9598..5b454347be9082883dccee0d84922c5aa7ca7da2 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 246cc34b45fc2fac76c06aee6b2eec594a62dd07..dedf41bb35746df6d43049e10d096e75a29d225b 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 0078e5514dcfa967bc9df6f7e4310e40fe6041c1..bec7fd72a0a7312a0cd90e4c59099fa1fc21dbb2 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 c4d74b799676e7006aa3a92d78a17d6b763611c4..12faaf8c6a94224bc398c5ed3f2139fb66c56142 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 c2ef678bc8e35aa38aacff6aa3065d46387699f5..236ffd74e9ab9caf52a143cfac415347d7b01df2 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 b1773376f80e8aeb78fb0824d41e22ad7682f7b8..2167d873ba422e62ca41c5813bc02112e515c6bb 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 6066f82a63058d2c7b1259c56e2f70cd33e393a8..660ee4121f7b2b5b0fac44a17d77fa0e7768b4df 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 8e62d23b5c53ddac2f24325ae2bc8a9d9d084501..9a46c9471fe04c5dce9bb11b5206f4099061f2cf 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',