fix committing file additions from a work tree with a path prefix New files were added under the wrong tree in the repository if the work tree has a path prefix. Fix this problem and catch it in the existing commit_with_path_prefix regression test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/lib/worktree.c b/lib/worktree.c
index d3a3569..68b5fac 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -5004,12 +5004,12 @@ write_tree(struct got_object_id **new_tree_id, int *nentries,
(ct->flags & GOT_COMMITABLE_ADDED))
continue;
- if (!got_path_is_child(pe->path, path_base_tree,
+ if (!got_path_is_child(ct->in_repo_path, path_base_tree,
strlen(path_base_tree)))
continue;
err = got_path_skip_common_ancestor(&child_path, path_base_tree,
- pe->path);
+ ct->in_repo_path);
if (err)
goto done;
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index b877e38..5e1cf69 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -444,8 +444,58 @@ function test_commit_path_prefix {
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got rm delta > /dev/null)
+ echo new > $testroot/wt/new
+ (cd $testroot/wt && got add new > /dev/null)
+
+ (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
+ > $testroot/stdout)
+
+ local commit3=`git_show_head $testroot/repo`
+ echo "A new" > $testroot/stdout.expected
+ echo "D delta" >> $testroot/stdout.expected
+ echo "Created commit $commit3" >> $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
+
+ echo "diff $commit2 $commit3" > $testroot/stdout.expected
+ echo -n 'blob - ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
+ | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
+ >> $testroot/stdout.expected
+ echo 'blob + /dev/null' >> $testroot/stdout.expected
+ echo '--- gamma/delta' >> $testroot/stdout.expected
+ echo '+++ /dev/null' >> $testroot/stdout.expected
+ echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
+ echo '-modified delta' >> $testroot/stdout.expected
+ echo 'blob - /dev/null' >> $testroot/stdout.expected
+ echo -n 'blob + ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
+ cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
+ >> $testroot/stdout.expected
+ echo '--- /dev/null' >> $testroot/stdout.expected
+ echo '+++ gamma/new' >> $testroot/stdout.expected
+ echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
+ echo '+new' >> $testroot/stdout.expected
+
+ got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
fi
test_done "$testroot" "$ret"
+ return "$ret"
}
function test_commit_dir_path {