All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, Erik Sandberg <mandolaerik@gmail.com>
Subject: [StGit PATCH 6/6] Handle failed pushes differently depending on cause
Date: Thu, 20 Mar 2008 01:32:02 +0100	[thread overview]
Message-ID: <20080320003202.13102.54792.stgit@yoghurt> (raw)
In-Reply-To: <20080320002604.13102.53757.stgit@yoghurt>

Specifically, if the push failed because of a merge conflict, the
patch should be applied but empty; and if it fails for any other
reason (such as a too-dirty worktree), the patch should not be
applied.

This fixes the data loss bug tested for by t3000.

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 stgit/lib/git.py         |   21 ++++++++++++++-------
 stgit/lib/transaction.py |    4 +++-
 t/t3000-dirty-merge.sh   |    2 +-
 3 files changed, 18 insertions(+), 9 deletions(-)


diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index cdfe885..35b9bbf 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -433,6 +433,9 @@ class Repository(RunWithEnv):
 class MergeException(exception.StgException):
     pass
 
+class MergeConflictException(MergeException):
+    pass
+
 class Index(RunWithEnv):
     def __init__(self, repository, filename):
         self.__repository = repository
@@ -517,14 +520,18 @@ class IndexAndWorktree(RunWithEnv):
         assert isinstance(ours, Tree)
         assert isinstance(theirs, Tree)
         try:
-            self.run(['git', 'merge-recursive', base.sha1, '--', ours.sha1,
-                      theirs.sha1],
-                     env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
-                             'GITHEAD_%s' % ours.sha1: 'current',
-                             'GITHEAD_%s' % theirs.sha1: 'patched'}
-                     ).cwd(self.__worktree.directory).discard_output()
+            r = self.run(['git', 'merge-recursive', base.sha1, '--', ours.sha1,
+                          theirs.sha1],
+                         env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
+                                 'GITHEAD_%s' % ours.sha1: 'current',
+                                 'GITHEAD_%s' % theirs.sha1: 'patched'}
+                         ).cwd(self.__worktree.directory)
+            r.discard_output()
         except run.RunException, e:
-            raise MergeException('Index/worktree dirty')
+            if r.exitcode == 1:
+                raise MergeConflictException()
+            else:
+                raise MergeException('Index/worktree dirty')
     def changed_files(self):
         return self.run(['git', 'diff-files', '--name-only']).output_lines()
     def update_index(self, files):
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 3613b15..2946a67 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -197,10 +197,12 @@ class StackTransaction(object):
                 tree = iw.index.write_tree()
                 self.__current_tree = tree
                 s = ' (modified)'
-            except git.MergeException:
+            except git.MergeConflictException:
                 tree = ours
                 merge_conflict = True
                 s = ' (conflict)'
+            except git.MergeException, e:
+                self.__halt(str(e))
         cd = cd.set_tree(tree)
         self.patches[pn] = self.__stack.repository.commit(cd)
         del self.unapplied[self.unapplied.index(pn)]
diff --git a/t/t3000-dirty-merge.sh b/t/t3000-dirty-merge.sh
index dd81c9e..d87bba1 100755
--- a/t/t3000-dirty-merge.sh
+++ b/t/t3000-dirty-merge.sh
@@ -22,7 +22,7 @@ test_expect_success 'Pop one patch and update the other' '
     stg refresh
 '
 
-test_expect_failure 'Push with dirty worktree' '
+test_expect_success 'Push with dirty worktree' '
     echo 4 > a &&
     [ "$(echo $(stg applied))" = "p1" ] &&
     [ "$(echo $(stg unapplied))" = "p2" ] &&

  parent reply	other threads:[~2008-03-20  0:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-20  0:31 [StGit PATCH 0/6] Two bugfixes Karl Hasselström
2008-03-20  0:31 ` [StGit PATCH 1/6] Use a special exit code for bugs Karl Hasselström
2008-03-20  0:31 ` [StGit PATCH 2/6] Make sure patches with no parents have an empty list of parents Karl Hasselström
2008-03-20  0:31 ` [StGit PATCH 3/6] Try uncommitting a commit with not exactly one parent Karl Hasselström
2008-03-20  0:31 ` [StGit PATCH 4/6] Make sure that we only uncommit commits with " Karl Hasselström
2008-03-20  0:31 ` [StGit PATCH 5/6] New test: conflicting push in dirty worktree Karl Hasselström
2008-03-20  0:32 ` Karl Hasselström [this message]
2008-03-20 15:19 ` [StGit PATCH 0/6] Two bugfixes Catalin Marinas
2008-03-24  8:35   ` Karl Hasselström
2008-03-24  9:16     ` Catalin Marinas
2008-03-24 18:12   ` Karl Hasselström
2008-03-25 10:46     ` Catalin Marinas
2008-03-25 11:05       ` Karl Hasselström
2008-03-25 15:27         ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080320003202.13102.54792.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mandolaerik@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.