fix 'got commit' from work tree with a path prefix
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 83 84
diff --git a/lib/worktree.c b/lib/worktree.c
index b41a123..e97e4a4 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2829,12 +2829,12 @@ match_ct_parent_path(int *match, struct got_commitable *ct, const char *path)
*match = 0;
- if (strchr(ct->path, '/') == NULL) {
+ if (strchr(ct->in_repo_path, '/') == NULL) {
*match = got_path_is_root_dir(path);
return NULL;
}
- err = got_path_dirname(&ct_parent_path, ct->path);
+ err = got_path_dirname(&ct_parent_path, ct->in_repo_path);
if (err)
return err;
*match = (strcmp(path, ct_parent_path) == 0);
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index fa62e4a..4cb5ebe 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -332,6 +332,55 @@ function test_commit_added_and_modified_in_same_dir {
test_done "$testroot" "$ret"
}
+function test_commit_path_prefix {
+ local testroot=`test_init commit_path_prefix`
+ local commit1=`git_show_head $testroot/repo`
+
+ got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified delta" > $testroot/wt/delta
+
+ (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
+
+ local commit2=`git_show_head $testroot/repo`
+ echo "M delta" > $testroot/stdout.expected
+ echo "Created commit $commit2" >> $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 $commit1 $commit2" > $testroot/stdout.expected
+ echo -n 'blob - ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
+ | cut -d' ' -f 1 >> $testroot/stdout.expected
+ echo -n 'blob + ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
+ cut -d' ' -f 1 >> $testroot/stdout.expected
+ echo '--- gamma/delta' >> $testroot/stdout.expected
+ echo '+++ gamma/delta' >> $testroot/stdout.expected
+ echo '@@ -1 +1 @@' >> $testroot/stdout.expected
+ echo '-delta' >> $testroot/stdout.expected
+ echo '+modified delta' >> $testroot/stdout.expected
+
+ got diff -r $testroot/repo $commit1 $commit2 > $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"
+}
+
run_test test_commit_basic
run_test test_commit_new_subdir
run_test test_commit_subdir
@@ -341,3 +390,4 @@ run_test test_commit_added_subdirs
run_test test_commit_rejects_conflicted_file
run_test test_commit_single_file_multiple
run_test test_commit_added_and_modified_in_same_dir
+run_test test_commit_path_prefix