Commit Diff


commit - 5a4e3316cf49f153a054aa30b611f65bc76ca40f4799fbd57655097b0e597e6a
commit + 80423302e7fa11406eae40d95698684cb77132ed93b4510e0a1a9db3f68a112c
blob - bf313afbf38972d7b1df888dee39005a9ed637077672f78168be7b2716dc510f
blob + d89a96a47916d3225c54bb2dfeea54e6faf188aaed98bc0c037ee79365e5c88f
--- got/got.1	
+++ got/got.1	
@@ -2621,7 +2621,7 @@ Show the status of each affected file, using the follo
 .It D Ta file was deleted
 .It d Ta file's deletion was prevented by local modifications
 .It A Ta new file was added
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .It ? Ta changes destined for an unversioned file were not merged
 .El
 .Pp
@@ -2764,7 +2764,7 @@ Show the status of each affected file, using the follo
 .It D Ta file was deleted
 .It d Ta file's deletion was prevented by local modifications
 .It A Ta new file was added
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .It ? Ta changes destined for an unversioned file were not merged
 .El
 .Pp
@@ -2927,13 +2927,14 @@ using the following status codes:
 .It D Ta file was deleted
 .It d Ta file's deletion was prevented by local modifications
 .It A Ta new file was added
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .It ? Ta changes destined for an unversioned file were not merged
 .El
 .Pp
 If merge conflicts occur, the rebase operation is interrupted and may
 be continued once conflicts have been resolved.
-If any files with destined changes are found to be missing or unversioned,
+If any files with destined changes are found to be missing, unversioned,
+or obstructed,
 or if files could not be deleted due to differences in deleted content,
 the rebase operation will be interrupted to prevent potentially incomplete
 changes from being committed to the repository without user intervention.
@@ -3196,13 +3197,14 @@ using the following status codes:
 .It D Ta file was deleted
 .It d Ta file's deletion was prevented by local modifications
 .It A Ta new file was added
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .It ? Ta changes destined for an unversioned file were not merged
 .El
 .Pp
 If merge conflicts occur, the histedit operation is interrupted and may
 be continued once conflicts have been resolved.
-If any files with destined changes are found to be missing or unversioned,
+If any files with destined changes are found to be missing, unversioned,
+or obstructed,
 or if files could not be deleted due to differences in deleted content,
 the histedit operation will be interrupted to prevent potentially incomplete
 changes from being committed to the repository without user intervention.
@@ -3497,13 +3499,14 @@ using the following status codes:
 .It D Ta file was deleted
 .It d Ta file's deletion was prevented by local modifications
 .It A Ta new file was added
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .It ? Ta changes destined for an unversioned file were not merged
 .El
 .Pp
 If merge conflicts occur, the merge operation is interrupted and conflicts
 must be resolved before the merge operation can continue.
-If any files with destined changes are found to be missing or unversioned,
+If any files with destined changes are found to be missing, unversioned,
+or obstructed,
 or if files could not be deleted due to differences in deleted content,
 the merge operation will be interrupted to prevent potentially incomplete
 changes from being committed to the repository without user intervention.
@@ -3726,7 +3729,7 @@ Show the status of each affected file, using the follo
 .It ! Ta changes destined for a missing file were not merged
 .It D Ta file was staged as deleted and still is deleted
 .It d Ta file's deletion was prevented by local modifications
-.It \(a~ Ta changes destined for a non-regular file were not merged
+.It \(a~ Ta changes obstructed by a non-regular file were not merged
 .El
 .Pp
 The options for
blob - a663c7966292554e6b0c78524dbfe5955e4cbde21fb69dc9b00831b02c011c96
blob + 6a6949d65688e42096b3f3a62d1aff046f9803e6d7dee656bfe06d5b2a127a38
--- got/got.c	
+++ got/got.c	
@@ -12051,7 +12051,8 @@ cmd_rebase(int argc, char *argv[])
 
 		print_merge_progress_stats(&upa);
 		if (upa.conflicts > 0 || upa.missing > 0 ||
-		    upa.not_deleted > 0 || upa.unversioned > 0) {
+		    upa.not_deleted > 0 || upa.unversioned > 0 ||
+		    upa.obstructed > 0) {
 			if (upa.conflicts > 0) {
 				error = show_rebase_merge_conflict(&qid->id,
 				    repo);
@@ -12070,7 +12071,7 @@ cmd_rebase(int argc, char *argv[])
 	}
 
 	if (upa.conflicts > 0 || upa.missing > 0 ||
-	    upa.not_deleted > 0 || upa.unversioned > 0) {
+	    upa.not_deleted > 0 || upa.unversioned > 0 || upa.obstructed > 0) {
 		error = got_worktree_rebase_postpone(worktree, fileindex);
 		if (error)
 			goto done;
@@ -13476,7 +13477,8 @@ cmd_histedit(int argc, char *argv[])
 
 		print_merge_progress_stats(&upa);
 		if (upa.conflicts > 0 || upa.missing > 0 ||
-		    upa.not_deleted > 0 || upa.unversioned > 0) {
+		    upa.not_deleted > 0 || upa.unversioned > 0 ||
+		    upa.obstructed > 0) {
 			if (upa.conflicts > 0) {
 				error = show_rebase_merge_conflict(
 				    hle->commit_id, repo);
@@ -13518,7 +13520,7 @@ cmd_histedit(int argc, char *argv[])
 	}
 
 	if (upa.conflicts > 0 || upa.missing > 0 ||
-	    upa.not_deleted > 0 || upa.unversioned > 0) {
+	    upa.not_deleted > 0 || upa.unversioned > 0 || upa.obstructed > 0) {
 		error = got_worktree_histedit_postpone(worktree, fileindex);
 		if (error)
 			goto done;
@@ -14031,7 +14033,7 @@ cmd_merge(int argc, char *argv[])
 			goto done;
 		printf("Merge of %s interrupted on request\n", branch_name);
 	} else if (upa.conflicts > 0 || upa.missing > 0 ||
-	    upa.not_deleted > 0 || upa.unversioned > 0) {
+	    upa.not_deleted > 0 || upa.unversioned > 0 || upa.obstructed > 0) {
 		error = got_worktree_merge_postpone(worktree, fileindex);
 		if (error)
 			goto done;
blob - 566130b850f98d43616e90d3ef387e3b7075d157b5aa4840b1821c97c6d70d02
blob + cd43af6f232741d02637e8dc2808ff3d8fc364083ce4687099a1be3fafdacf10
--- lib/worktree.c	
+++ lib/worktree.c	
@@ -3345,6 +3345,21 @@ merge_file_cb(void *arg, struct got_blob_object *blob1
 					goto done;
 			}
 		} else {
+			if (lstat(ondisk_path, &sb) == -1) {
+				if (errno != ENOENT && errno != ENOTDIR) {
+					err = got_error_from_errno2("stat",
+					    ondisk_path);
+					goto done;
+				}
+			} else {
+				if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode))
+					status = GOT_STATUS_UNVERSIONED;
+				else
+					status = GOT_STATUS_OBSTRUCTED;
+				err = (*a->progress_cb)(a->progress_arg,
+				    status, path2);
+				goto done;
+			}
 			err = add_file(a->worktree, a->fileindex, NULL,
 			     ondisk_path, path2, blob2, mode2,
 			     0, 0, 1, a->allow_bad_symlinks,
blob - abb1d21a5bd593d895aaff6c372a0b1a7fcf58bba570741a03a8dc81567717d7
blob + 3b4c7ae2addb09679628c1b2c01dae0e49a2be5d30177ab3628e96d24c92fd79
--- regress/cmdline/histedit.sh	
+++ regress/cmdline/histedit.sh	
@@ -3030,17 +3030,17 @@ test_histedit_added_file() {
 	# +2f81c7988242 -> no-op change: add new file
 	echo new > $testroot/wt/new
 
-	(cd $testroot/wt && got histedit -f > $testroot/stdout)
+	(cd $testroot/wt && got histedit -f > $testroot/stdout \
+		2> $testroot/stderr)
 	local new_commit=`git_show_head $testroot/repo`
 
 	local short_commit2=`trim_obj_id 12 $commit2`
 	local short_new_commit=`trim_obj_id 12 $new_commit`
 
-	echo "A  new" > $testroot/stdout.expected
-	echo "$short_commit2 -> $short_new_commit: add new file" \
-		>> $testroot/stdout.expected
-	echo "Switching work tree to refs/heads/master" \
-		>> $testroot/stdout.expected
+	cat > $testroot/stdout.expected <<EOF
+?  new
+Files not merged because an unversioned file was found in the work tree: 1
+EOF
 
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret=$?
@@ -3050,6 +3050,17 @@ test_histedit_added_file() {
 		return 1
 	fi
 
+	cat > $testroot/stderr.expected <<EOF
+got: changes destined for some files were not yet merged and should be merged manually if required before the histedit operation is continued
+EOF
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
 	test_done "$testroot" "$ret"
 }
 
blob - cb251614041ee90a104638ee7ef11a3237360bb800fae8bdf0a10723d038fcd9
blob + e8b1cfa9c442fe171483597aef029d231a2d4477c338047edcd9e87606457438
--- regress/cmdline/merge.sh	
+++ regress/cmdline/merge.sh	
@@ -2331,6 +2331,367 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_merge_adds_ignored_file() {
+	local testroot=`test_init merge_adds_ignored_file`
+	local commit0=`git_show_head $testroot/repo`
+	local commit0_author_time=`git_show_author_time $testroot/repo`
+
+	git -C $testroot/repo checkout -q -b newbranch
+	echo "new file on branch" > $testroot/repo/gamma/new
+	git -C $testroot/repo add gamma/new > /dev/null
+	git_commit $testroot/repo -m "committing to new file on newbranch"
+	local branch_commit=`git_show_branch_head $testroot/repo newbranch`
+
+	git -C $testroot/repo checkout -q master
+	echo gamma/new > $testroot/repo/.gitignore
+	git -C $testroot/repo add .gitignore > /dev/null
+	echo "ignoring new file on master branch" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "committing to zeta on master"
+	local master_commit=`git_show_head $testroot/repo`
+
+	got checkout -b master $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
+
+	echo 'this file is being ignored' > $testroot/wt/gamma/new
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo -n > $testroot/stdout.expected
+
+	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
+
+	(cd $testroot/wt && got status -I > $testroot/stdout)
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+EOF
+	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
+
+	cat > $testroot/stderr.expected <<EOF
+got: changes destined for some files were not yet merged and should be merged manually if required before the merge operation is continued
+EOF
+	(cd $testroot/wt && got merge newbranch \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got merge succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	local merge_commit=`git_show_head $testroot/repo`
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+Files not merged because an unversioned file was found in the work tree: 1
+EOF
+	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
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_merge_adds_ignored_symlink() {
+	local testroot=`test_init merge_adds_ignored_symlink`
+	local commit0=`git_show_head $testroot/repo`
+	local commit0_author_time=`git_show_author_time $testroot/repo`
+
+	git -C $testroot/repo checkout -q -b newbranch
+	echo "new file on branch" > $testroot/repo/gamma/new
+	git -C $testroot/repo add gamma/new > /dev/null
+	git_commit $testroot/repo -m "committing to new file on newbranch"
+	local branch_commit=`git_show_branch_head $testroot/repo newbranch`
+
+	git -C $testroot/repo checkout -q master
+	echo gamma/new > $testroot/repo/.gitignore
+	git -C $testroot/repo add .gitignore > /dev/null
+	echo "ignoring new file on master branch" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "committing to zeta on master"
+	local master_commit=`git_show_head $testroot/repo`
+
+	got checkout -b master $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
+
+	ln -s ../alpha $testroot/wt/gamma/new
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo -n > $testroot/stdout.expected
+
+	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
+
+	(cd $testroot/wt && got status -I > $testroot/stdout)
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+EOF
+	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
+
+	cat > $testroot/stderr.expected <<EOF
+got: changes destined for some files were not yet merged and should be merged manually if required before the merge operation is continued
+EOF
+	(cd $testroot/wt && got merge newbranch \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got merge succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	local merge_commit=`git_show_head $testroot/repo`
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+Files not merged because an unversioned file was found in the work tree: 1
+EOF
+	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
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_merge_adds_ignored_dangling_symlink() {
+	local testroot=`test_init merge_adds_ignored_dangling_symlink`
+	local commit0=`git_show_head $testroot/repo`
+	local commit0_author_time=`git_show_author_time $testroot/repo`
+
+	git -C $testroot/repo checkout -q -b newbranch
+	echo "new file on branch" > $testroot/repo/gamma/new
+	git -C $testroot/repo add gamma/new > /dev/null
+	git_commit $testroot/repo -m "committing to new file on newbranch"
+	local branch_commit=`git_show_branch_head $testroot/repo newbranch`
+
+	git -C $testroot/repo checkout -q master
+	echo gamma/new > $testroot/repo/.gitignore
+	git -C $testroot/repo add .gitignore > /dev/null
+	echo "ignoring new file on master branch" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "committing to zeta on master"
+	local master_commit=`git_show_head $testroot/repo`
+
+	got checkout -b master $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
+
+	ln -f -s ../nonexistent $testroot/wt/gamma/new
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo -n > $testroot/stdout.expected
+
+	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
+
+	(cd $testroot/wt && got status -I > $testroot/stdout)
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+EOF
+	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
+
+	cat > $testroot/stderr.expected <<EOF
+got: changes destined for some files were not yet merged and should be merged manually if required before the merge operation is continued
+EOF
+	(cd $testroot/wt && got merge newbranch \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got merge succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	local merge_commit=`git_show_head $testroot/repo`
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new
+Files not merged because an unversioned file was found in the work tree: 1
+EOF
+	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
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
+test_merge_adds_ignored_directory() {
+	local testroot=`test_init merge_adds_ignored_directory`
+	local commit0=`git_show_head $testroot/repo`
+	local commit0_author_time=`git_show_author_time $testroot/repo`
+
+	git -C $testroot/repo checkout -q -b newbranch
+	echo "new file on branch" > $testroot/repo/gamma/new
+	git -C $testroot/repo add gamma/new > /dev/null
+	git_commit $testroot/repo -m "committing to new file on newbranch"
+	local branch_commit=`git_show_branch_head $testroot/repo newbranch`
+
+	git -C $testroot/repo checkout -q master
+	echo gamma/new > $testroot/repo/.gitignore
+	git -C $testroot/repo add .gitignore > /dev/null
+	echo "ignoring new file on master branch" > $testroot/repo/epsilon/zeta
+	git_commit $testroot/repo -m "committing to zeta on master"
+	local master_commit=`git_show_head $testroot/repo`
+
+	got checkout -b master $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
+
+	mkdir -p $testroot/wt/gamma/new/
+	echo 'this file is being ignored' > $testroot/wt/gamma/new/ignored
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo -n > $testroot/stdout.expected
+
+	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
+
+	(cd $testroot/wt && got status -I > $testroot/stdout)
+
+	cat > $testroot/stdout.expected <<EOF
+?  gamma/new/ignored
+EOF
+	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
+
+	cat > $testroot/stderr.expected <<EOF
+got: changes destined for some files were not yet merged and should be merged manually if required before the merge operation is continued
+EOF
+	(cd $testroot/wt && got merge newbranch \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "got merge succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	local merge_commit=`git_show_head $testroot/repo`
+
+	cat > $testroot/stdout.expected <<EOF
+~  gamma/new
+File paths obstructed by a non-regular file: 1
+EOF
+	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
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_merge_basic
 run_test test_merge_forward
@@ -2352,3 +2713,7 @@ run_test test_merge_fetched_branch
 run_test test_merge_fetched_branch_remote
 run_test test_merge_tag
 run_test test_merge_tag_abort
+run_test test_merge_adds_ignored_file
+run_test test_merge_adds_ignored_symlink
+run_test test_merge_adds_ignored_dangling_symlink
+run_test test_merge_adds_ignored_directory