Commit 5cc266baadfb13464b72e1ccbec0462eb641f0b6

Stefan Sperling 2019-01-06T13:14:54

make 'got update' remove directories in a checkout with path prefix

diff --git a/lib/worktree.c b/lib/worktree.c
index b9ce306..68c4f29 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -798,9 +798,7 @@ remove_missing_files(struct got_worktree *worktree, const char *path,
 	a.fileindex = fileindex;
 	a.entries = entries;
 	a.missing_entries.nentries = 0;
-	a.current_subdir = path;
-	while (a.current_subdir[0] == '/')
-		a.current_subdir++;
+	a.current_subdir = apply_path_prefix(worktree, path);
 	TAILQ_INIT(&a.missing_entries.entries);
 	err = got_fileindex_for_each_entry(fileindex, collect_missing_file, &a);
 	if (err)
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index cc23e63..7364849 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -190,7 +190,54 @@ function test_update_deletes_dir {
 	test_done "$testroot" "$ret"
 }
 
+function test_update_deletes_dir_with_path_prefix {
+	local testroot=`test_init update_deletes_dir_with_path_prefix`
+	local first_rev=`git_show_head $testroot/repo`
+
+	mkdir $testroot/repo/epsilon/psi
+	echo mu > $testroot/repo/epsilon/psi/mu
+	(cd $testroot/repo && git add .)
+	git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
+
+	# check out the epsilon/ sub-tree
+	got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
+	if [ "$?" != "0" ]; then
+		test_done "$testroot" "$?"
+		return 1
+	fi
+
+	# update back to first commit and expect psi/mu to be deleted
+	echo "D  psi/mu" > $testroot/stdout.expected
+	echo "Updated to commit $first_rev" >> $testroot/stdout.expected
+
+	(cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
+
+	cmp $testroot/stdout.expected $testroot/stdout
+	if [ "$?" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$?"
+		return 1
+	fi
+
+	if [ -e $testroot/wt/psi ]; then
+		echo "removed dir psi still exists on disk" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	echo "zeta" >> $testroot/content.expected
+	cat $testroot/wt/zeta > $testroot/content
+
+	cmp $testroot/content.expected $testroot/content
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/content.expected $testroot/content
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_update_basic
 run_test test_update_adds_file
 run_test test_update_deletes_file
 run_test test_update_deletes_dir
+run_test test_update_deletes_dir_with_path_prefix