Commit Diff


commit - efdf8bc63f43a23d5fa80ba23dab206cfb41ec2b00e87d7b3ea147d78471311f
commit + 5202bcb0ad315ef2e0b80d183118906724921094fbbea43bd892aef98fc50dd7
blob - 6a6949d65688e42096b3f3a62d1aff046f9803e6d7dee656bfe06d5b2a127a38
blob + 4206c40daec04aac080dc80d06c5f9aa048104280629622eddabcc013f188b45
--- got/got.c	
+++ got/got.c	
@@ -9039,12 +9039,16 @@ commit_path_changed_in_worktree(struct wt_commitable_p
     struct got_repository *repo)
 {
 	const struct got_error		*err;
-	struct got_pathlist_head	 paths;
+	struct got_pathlist_head	 paths, wt_paths;
+	struct got_pathlist_head	*status_paths;
+	struct got_pathlist_entry	*pe;
 	struct got_commit_object	*commit = NULL, *pcommit = NULL;
 	struct got_tree_object		*tree = NULL, *ptree = NULL;
 	struct got_object_qid		*pid;
+	const char			*prefix;
 
 	RB_INIT(&paths);
+	RB_INIT(&wt_paths);
 
 	err = got_object_open_as_commit(&commit, repo, id);
 	if (err)
@@ -9072,7 +9076,31 @@ commit_path_changed_in_worktree(struct wt_commitable_p
 	if (err)
 		goto done;
 
-	err = got_worktree_status(worktree, &paths, repo, 0,
+	prefix = got_worktree_get_path_prefix(worktree);
+	if (!got_path_is_root_dir(prefix)) {
+		RB_FOREACH(pe, got_pathlist_head, &paths) {
+			char *abspath, *wt_path;
+
+			if (asprintf(&abspath, "/%s", pe->path) == -1) {
+				err = got_error_from_errno("asprintf");
+				goto done;
+			}
+			err = got_path_skip_common_ancestor(&wt_path,
+			    prefix, abspath);
+			free(abspath);
+			if (err)
+				goto done;
+
+			err = got_pathlist_insert(NULL, &wt_paths, wt_path,
+			    NULL);
+			if (err)
+				goto done;
+		}
+		status_paths = &wt_paths;
+	} else
+		status_paths = &paths;
+
+	err = got_worktree_status(worktree, status_paths, repo, 0,
 	    worktree_has_commitable_path, wcpa, check_cancelled, NULL);
 	if (err && err->code == GOT_ERR_FILE_MODIFIED) {
 		/*
@@ -9084,6 +9112,7 @@ commit_path_changed_in_worktree(struct wt_commitable_p
 
 done:
 	got_pathlist_free(&paths, GOT_PATHLIST_FREE_ALL);
+	got_pathlist_free(&wt_paths, GOT_PATHLIST_FREE_PATH);
 	if (commit)
 		got_object_commit_close(commit);
 	if (pcommit)
blob - 02c7f0e06bd6a8302157b97bde5d5822b201c47f6f7cf02a7caae76ede80b639
blob + 0b0b27c574574bb3bdb85c100e1c3f3b54d3054078291c9d362cc86d06e1f2c4
--- regress/cmdline/revert.sh	
+++ regress/cmdline/revert.sh	
@@ -2078,6 +2078,59 @@ test_revert_partially_staged_file() {
 	test_done "$testroot" "$ret"
 }
 
+test_revert_backout_with_path_prefix() {
+	local testroot=`test_init revert_backout_with_path_prefix`
+
+	got checkout $testroot/repo $testroot/wt2 > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified zeta" > $testroot/wt2/epsilon/zeta
+	(cd $testroot/wt2 && got commit -m 'modify zeta' > /dev/null)
+	local commit_id=`git_show_head $testroot/repo`
+
+	got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got backout "$commit_id" >/dev/null)
+
+	echo "unversioned file" > $testroot/wt/epsilon
+
+	echo 'R  zeta' > $testroot/stdout.expected
+
+	# This used to fail with:
+	# "got: fopen: $testroot/wt/epsilon/.cvsignore: Not a directory"
+	(cd $testroot/wt && got revert -R . > $testroot/stdout)
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified zeta" > $testroot/content.expected
+	cat $testroot/wt/zeta > $testroot/content
+
+	cmp -s $testroot/content.expected $testroot/content
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/content.expected $testroot/content
+	fi
+	test_done "$testroot" "$ret"
+
+}
+
 test_parseargs "$@"
 run_test test_revert_basic
 run_test test_revert_rm
@@ -2100,3 +2153,4 @@ run_test test_revert_umask
 run_test test_revert_patch_binary
 run_test test_revert_staged_file
 run_test test_revert_partially_staged_file
+run_test test_revert_backout_with_path_prefix