- # file exists in origin
- if orig_hash:
- # modified in both
- if file1_hash and file2_hash:
- # if modes are the same (git-read-tree probably dealt with it)
- if file1_hash == file2_hash:
- if os.system('git-update-index --cacheinfo %s %s %s'
- % (file1_mode, file1_hash, path)) != 0:
- print >> sys.stderr, 'Error: git-update-index failed'
- __conflict(path)
- return 1
- if os.system('git-checkout-index -u -f -- %s' % path):
- print >> sys.stderr, 'Error: git-checkout-index failed'
- __conflict(path)
- return 1
- if file1_mode != file2_mode:
- print >> sys.stderr, \
- 'Error: File added in both, permissions conflict'
- __conflict(path)
- return 1
- # 3-way merge
- else:
- merge_ok = os.system(str(merger) % {'branch1': src1,
- 'ancestor': orig,
- 'branch2': src2,
- 'output': path }) == 0
-
- if merge_ok:
- os.system('git-update-index -- %s' % path)
- __remove_files(orig_hash, file1_hash, file2_hash)
- return 0
- else:
- print >> sys.stderr, \
- 'Error: three-way merge tool failed for file "%s"' \
- % path
- # reset the cache to the first branch
- os.system('git-update-index --cacheinfo %s %s %s'
- % (file1_mode, file1_hash, path))
-
- if config.get('stgit', 'autoimerge') == 'yes':
- print >> sys.stderr, \
- 'Trying the interactive merge'
- try:
- interactive_merge(path)
- except GitMergeException, ex:
- # interactive merge failed
- print >> sys.stderr, str(ex)
- if str(keeporig) != 'yes':
- __remove_files(orig_hash, file1_hash,
- file2_hash)
- __conflict(path)
- return 1
- # successful interactive merge
- os.system('git-update-index -- %s' % path)
- __remove_files(orig_hash, file1_hash, file2_hash)
- return 0
- else:
- # no interactive merge, just mark it as conflict
- if str(keeporig) != 'yes':
- __remove_files(orig_hash, file1_hash, file2_hash)
- __conflict(path)
- return 1
-
- # file deleted in both or deleted in one and unchanged in the other
- elif not (file1_hash or file2_hash) \
- or file1_hash == orig_hash or file2_hash == orig_hash:
- if os.path.exists(path):
- os.remove(path)
- __remove_files(orig_hash, file1_hash, file2_hash)
- return os.system('git-update-index --remove -- %s' % path)
- # file deleted in one and changed in the other
+ try:
+ # Check whether we have all the files for the merge.
+ if not (stages['current'] and stages['patched']):
+ raise GitMergeException('Cannot run the interactive merge')
+
+ if stages['ancestor']:
+ three_way = True
+ files_dict = {'branch1': stages['current'],
+ 'ancestor': stages['ancestor'],
+ 'branch2': stages['patched'],
+ 'output': filename}
+ imerger = config.get('stgit.i3merge')