From: Catalin Marinas <catalin.marinas@arm.com>
To: git@vger.kernel.org, "Karl Hasselström" <kha@treskal.com>
Subject: [StGit PATCH 2/4] Add automatic git-mergetool invocation to the new infrastructure
Date: Tue, 17 Mar 2009 11:08:58 +0000 [thread overview]
Message-ID: <20090317110858.27748.21534.stgit@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20090317110721.27748.10295.stgit@pc1117.cambridge.arm.com>
This patch adds the IndexAndWorktree.mergetool() function responsible
for calling 'git mergetool' to interactively solve conflicts. The
function may also be called from IndexAndWorktree.merge() if the
standard 'git merge-recursive' fails and 'interactive == True'. The
'allow_interactive' parameter is passed to Transaction.push_patch() from
the functions allowing interactive merging.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
stgit/commands/edit.py | 2 +-
stgit/commands/goto.py | 2 +-
stgit/lib/git.py | 19 ++++++++++++++++---
stgit/lib/transaction.py | 7 +++++--
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index ed785aa..42eb792 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -128,7 +128,7 @@ def func(parser, options, args):
trans.patches[patchname] = stack.repository.commit(cd)
try:
for pn in popped:
- trans.push_patch(pn, iw)
+ trans.push_patch(pn, iw, allow_interactive = True)
except transaction.TransactionHalted:
pass
try:
diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py
index 480266a..66f49df 100644
--- a/stgit/commands/goto.py
+++ b/stgit/commands/goto.py
@@ -48,7 +48,7 @@ def func(parser, options, args):
elif patch in trans.unapplied:
try:
for pn in trans.unapplied[:trans.unapplied.index(patch)+1]:
- trans.push_patch(pn, iw)
+ trans.push_patch(pn, iw, allow_interactive = True)
except transaction.TransactionHalted:
pass
elif patch in trans.hidden:
diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 07079b8..e0a3c96 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -824,7 +824,7 @@ class IndexAndWorktree(RunWithEnvCwd):
).discard_output()
except run.RunException:
raise CheckoutException('Index/workdir dirty')
- def merge(self, base, ours, theirs):
+ def merge(self, base, ours, theirs, interactive = False):
assert isinstance(base, Tree)
assert isinstance(ours, Tree)
assert isinstance(theirs, Tree)
@@ -838,10 +838,23 @@ class IndexAndWorktree(RunWithEnvCwd):
output = r.output_lines()
if r.exitcode:
# There were conflicts
- conflicts = [l for l in output if l.startswith('CONFLICT')]
- raise MergeConflictException(conflicts)
+ if interactive:
+ self.mergetool()
+ else:
+ conflicts = [l for l in output if l.startswith('CONFLICT')]
+ raise MergeConflictException(conflicts)
except run.RunException, e:
raise MergeException('Index/worktree dirty')
+ def mergetool(self, files = ()):
+ """Invoke 'git mergetool' on the current IndexAndWorktree to resolve
+ any outstanding conflicts. If 'not files', all the files in an
+ unmerged state will be processed."""
+ run.Run(['git', 'mergetool'] + list(files)).returns([0, 1]).run()
+ # check for unmerged entries (prepend 'CONFLICT ' for consistency with
+ # merge())
+ conflicts = ['CONFLICT ' + f for f in self.index.conflicts()]
+ if conflicts:
+ raise MergeConflictException(conflicts)
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 a88d289..4b5398a 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -8,6 +8,7 @@ from stgit import exception, utils
from stgit.utils import any, all
from stgit.out import *
from stgit.lib import git, log
+from stgit.config import config
class TransactionException(exception.StgException):
"""Exception raised when something goes wrong with a
@@ -296,7 +297,7 @@ class StackTransaction(object):
out.info('Deleted %s%s' % (pn, s))
return popped
- def push_patch(self, pn, iw = None):
+ def push_patch(self, pn, iw = None, allow_interactive = False):
"""Attempt to push the named patch. If this results in conflicts,
halts the transaction. If index+worktree are given, spill any
conflicts to them."""
@@ -319,7 +320,9 @@ class StackTransaction(object):
except git.CheckoutException:
self.__halt('Index/worktree dirty')
try:
- iw.merge(base, ours, theirs)
+ interactive = (allow_interactive and
+ config.get('stgit.autoimerge') == 'yes')
+ iw.merge(base, ours, theirs, interactive = interactive)
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
next prev parent reply other threads:[~2009-03-17 11:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-17 11:08 [StGit PATCH 0/4] Reposting udpated patches Catalin Marinas
2009-03-17 11:08 ` [StGit PATCH 1/4] Add mergetool support to the classic StGit infrastructure Catalin Marinas
2009-03-17 15:29 ` Karl Hasselström
2009-03-17 11:08 ` Catalin Marinas [this message]
2009-03-17 15:30 ` [StGit PATCH 2/4] Add automatic git-mergetool invocation to the new infrastructure Karl Hasselström
2009-03-17 11:09 ` [StGit PATCH 3/4] Convert "float" to the lib infrastructure Catalin Marinas
2009-03-17 16:34 ` Karl Hasselström
2009-03-17 11:09 ` [StGit PATCH 4/4] Use a default "hidden" argument in StackTransaction.reorder_patches Catalin Marinas
2009-03-17 16:38 ` 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=20090317110858.27748.21534.stgit@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=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