From: Catalin Marinas <catalin.marinas@gmail.com>
To: "Karl Hasselström" <kha@treskal.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH] Print conflict details with the new infrastructure (bug #11181)
Date: Wed, 03 Dec 2008 21:38:13 +0000 [thread overview]
Message-ID: <20081203213813.9924.62751.stgit@localhost.localdomain> (raw)
The patch modifies the IndexAndWorkTree.merge() function to display
pass the conflict information (files) when raising an exception. The
logic is similar to the one in the old infrastructure.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
stgit/lib/git.py | 15 ++++++++++-----
stgit/lib/transaction.py | 11 ++++++++---
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 0a208ef..e2b4266 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -677,6 +677,9 @@ class MergeException(exception.StgException):
class MergeConflictException(MergeException):
"""Exception raised when a merge fails due to conflicts."""
+ def __init__(self, conflicts):
+ MergeException.__init__(self)
+ self.conflicts = conflicts
class Index(RunWithEnv):
"""Represents a git index file."""
@@ -829,12 +832,14 @@ class IndexAndWorktree(RunWithEnvCwd):
env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
'GITHEAD_%s' % ours.sha1: 'current',
'GITHEAD_%s' % theirs.sha1: 'patched'})
- r.discard_output()
+ r.returns([0, 1])
+ output = r.output_lines()
+ if r.exitcode:
+ # There were conflicts
+ conflicts = [l for l in output if l.startswith('CONFLICT')]
+ raise MergeConflictException(conflicts)
except run.RunException, e:
- if r.exitcode == 1:
- raise MergeConflictException()
- else:
- raise MergeException('Index/worktree dirty')
+ raise MergeException('Index/worktree dirty')
def changed_files(self, tree, pathlimits = []):
"""Return the set of files in the worktree that have changed with
respect to C{tree}. The listing is optionally restricted to
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 0f414d8..54de127 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -94,6 +94,7 @@ class StackTransaction(object):
self.__base = self.__stack.base
self.__discard_changes = discard_changes
self.__bad_head = None
+ self.__conflicts = None
if isinstance(allow_conflicts, bool):
self.__allow_conflicts = lambda trans: allow_conflicts
else:
@@ -201,7 +202,10 @@ class StackTransaction(object):
self.__stack.set_head(new_head, self.__msg)
if self.__error:
- out.error(self.__error)
+ if self.__conflicts:
+ out.error(*([self.__error] + self.__conflicts))
+ else:
+ out.error(self.__error)
# Write patches.
def write(msg):
@@ -311,9 +315,10 @@ class StackTransaction(object):
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
- except git.MergeConflictException:
+ except git.MergeConflictException, e:
tree = ours
merge_conflict = True
+ self.__conflicts = e.conflicts
s = ' (conflict)'
except git.MergeException, e:
self.__halt(str(e))
@@ -344,7 +349,7 @@ class StackTransaction(object):
# Save this update so that we can run it a little later.
self.__conflicting_push = update
- self.__halt('Merge conflict')
+ self.__halt("%d merge conflict(s)" % len(self.__conflicts))
else:
# Update immediately.
update()
next reply other threads:[~2008-12-03 21:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-03 21:38 Catalin Marinas [this message]
2008-12-04 9:30 ` [StGit PATCH] Print conflict details with the new infrastructure (bug #11181) Karl Hasselström
-- strict thread matches above, loose matches on Subject: below --
2008-12-02 14:40 Catalin Marinas
2008-12-02 15:43 ` Karl Hasselström
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=20081203213813.9924.62751.stgit@localhost.localdomain \
--to=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).