summaryrefslogtreecommitdiff
path: root/merge.c
diff options
context:
space:
mode:
authorMartin Ågren <martin.agren@gmail.com>2018-02-28 19:07:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-28 19:15:51 (GMT)
commit5790d25881a60a1c3a780e997a59774e48c2c026 (patch)
tree012c51b4d3eb8fef81294f69d363151181c82b53 /merge.c
parent51d3f43d2fd7f93cd19494eef4aef712fad597c2 (diff)
downloadgit-5790d25881a60a1c3a780e997a59774e48c2c026.zip
git-5790d25881a60a1c3a780e997a59774e48c2c026.tar.gz
git-5790d25881a60a1c3a780e997a59774e48c2c026.tar.bz2
merge: always roll back lock in `checkout_fast_forward()`
This function originated in builtin/merge.c. It was moved to merge.c in commit db699a8a1f (Move try_merge_command and checkout_fast_forward to libgit.a, 2012-10-26), but was used from sequencer.c even before that. If a problem occurs, the function returns without rolling back the lockfile. Teach it to do so. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge.c')
-rw-r--r--merge.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/merge.c b/merge.c
index 195b578..f06a477 100644
--- a/merge.c
+++ b/merge.c
@@ -113,17 +113,23 @@ int checkout_fast_forward(const struct object_id *head,
setup_unpack_trees_porcelain(&opts, "merge");
trees[nr_trees] = parse_tree_indirect(head);
- if (!trees[nr_trees++])
+ if (!trees[nr_trees++]) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
trees[nr_trees] = parse_tree_indirect(remote);
- if (!trees[nr_trees++])
+ if (!trees[nr_trees++]) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
for (i = 0; i < nr_trees; i++) {
parse_tree(trees[i]);
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
}
- if (unpack_trees(nr_trees, t, &opts))
+ if (unpack_trees(nr_trees, t, &opts)) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
return error(_("unable to write new index file"));
return 0;