Commit 8b692cd00bf22ee0c1455a6d17590b0e2f207a87

Stefan Sperling 2019-10-21T09:04:57

remove lock files, as intended, when reintegrate gets aborted

diff --git a/lib/worktree.c b/lib/worktree.c
index c4df32a..3c6178d 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -5831,10 +5831,23 @@ got_worktree_integrate_abort(struct got_worktree *worktree,
     struct got_fileindex *fileindex, struct got_repository *repo,
     struct got_reference *branch_ref, struct got_reference *base_branch_ref)
 {
+	const struct got_error *err = NULL, *unlockerr = NULL;
+
+	got_fileindex_free(fileindex);
+
+	err = lock_worktree(worktree, LOCK_SH);
+
+	unlockerr = got_ref_unlock(branch_ref);
+	if (unlockerr && err == NULL)
+		err = unlockerr;
 	got_ref_close(branch_ref);
+
+	unlockerr = got_ref_unlock(base_branch_ref);
+	if (unlockerr && err == NULL)
+		err = unlockerr;
 	got_ref_close(base_branch_ref);
-	got_fileindex_free(fileindex);
-	return lock_worktree(worktree, LOCK_SH);
+
+	return err;
 }
 
 struct check_stage_ok_arg {
diff --git a/regress/cmdline/integrate.sh b/regress/cmdline/integrate.sh
index 35a98a4..5c925e2 100755
--- a/regress/cmdline/integrate.sh
+++ b/regress/cmdline/integrate.sh
@@ -220,6 +220,23 @@ function test_integrate_requires_rebase_first {
 	echo "commit $new_commit1" >> $testroot/stdout.expected
 	echo "commit $init_commit" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/repo && got branch -l > $testroot/stdout)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "got rebase failed unexpectedly"
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "  master: $master_commit" > $testroot/stdout.expected
+	echo "  newbranch: $new_commit2" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then