Commit Diff


commit - e6436a3ca5a32f64391f231b96417490fea680f9f5255f21f7629c17316f4727
commit + cd1f027e43542f5d4e12c7eccf394fc605afa77ae19647971dac32900f0ee7c3
blob - 96e5ff394bf431dbe6c868958ebce6d62b3be579f1520e25f1384d97d4672723
blob + 23c520659f6d411f84b61dbf213ac2133369c0ddf6117c71da3ec3170f0ee29c
--- lib/worktree.c	
+++ lib/worktree.c	
@@ -1155,7 +1155,7 @@ install_blob(struct got_worktree *worktree, const char
     const char *path, mode_t te_mode, mode_t st_mode,
     struct got_blob_object *blob, int restoring_missing_file,
     int reverting_versioned_file, int installing_bad_symlink,
-    int path_is_unversioned, int *update_timestamps,
+    int path_is_unversioned, int adding_merged_file, int *update_timestamps,
     struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg);
 
@@ -1302,7 +1302,7 @@ install_symlink(int *is_bad_symlink, struct got_worktr
 			return install_blob(worktree, ondisk_path, path,
 			    GOT_DEFAULT_FILE_MODE, GOT_DEFAULT_FILE_MODE, blob,
 			    restoring_missing_file, reverting_versioned_file,
-			    1, path_is_unversioned, NULL, repo, progress_cb,
+			    1, path_is_unversioned, 0, NULL, repo, progress_cb,
 			    progress_arg);
 		}
 		if (len > 0) {
@@ -1326,7 +1326,7 @@ install_symlink(int *is_bad_symlink, struct got_worktr
 		err = install_blob(worktree, ondisk_path, path,
 		    GOT_DEFAULT_FILE_MODE, GOT_DEFAULT_FILE_MODE, blob,
 		    restoring_missing_file, reverting_versioned_file, 1,
-		    path_is_unversioned, NULL, repo,
+		    path_is_unversioned, 0, NULL, repo,
 		    progress_cb, progress_arg);
 		return err;
 	}
@@ -1390,7 +1390,7 @@ install_symlink(int *is_bad_symlink, struct got_worktr
 			err = install_blob(worktree, ondisk_path, path,
 			    GOT_DEFAULT_FILE_MODE, GOT_DEFAULT_FILE_MODE, blob,
 			    restoring_missing_file, reverting_versioned_file, 1,
-			    path_is_unversioned, NULL, repo,
+			    path_is_unversioned, 0, NULL, repo,
 			    progress_cb, progress_arg);
 		} else if (errno == ENOTDIR) {
 			err = got_error_path(ondisk_path,
@@ -1410,8 +1410,8 @@ install_blob(struct got_worktree *worktree, const char
     const char *path, mode_t te_mode, mode_t st_mode,
     struct got_blob_object *blob, int restoring_missing_file,
     int reverting_versioned_file, int installing_bad_symlink,
-    int path_is_unversioned, int *update_timestamps,
-    struct got_repository *repo,
+    int path_is_unversioned, int adding_merged_file,
+    int *update_timestamps, struct got_repository *repo,
     got_worktree_checkout_cb progress_cb, void *progress_arg)
 {
 	const struct got_error *err = NULL;
@@ -1450,7 +1450,8 @@ install_blob(struct got_worktree *worktree, const char
 				if (update_timestamps)
 					*update_timestamps = 0;
 				err = (*progress_cb)(progress_arg,
-				    GOT_STATUS_EXISTS, path);
+				    adding_merged_file ?
+				    GOT_STATUS_ADD : GOT_STATUS_EXISTS, path);
 				goto done;
 			}
 			if (!(S_ISLNK(st_mode) && S_ISREG(te_mode)) &&
@@ -2150,7 +2151,7 @@ update_blob(struct got_worktree *worktree,
 			err = install_blob(worktree, ondisk_path, path,
 			    te->mode, sb.st_mode, blob,
 			    status == GOT_STATUS_MISSING, 0, 0,
-			    status == GOT_STATUS_UNVERSIONED,
+			    status == GOT_STATUS_UNVERSIONED, 0,
 			    &update_timestamps,
 			    repo, progress_cb, progress_arg);
 		}
@@ -2966,7 +2967,7 @@ add_file(struct got_worktree *worktree, struct got_fil
 		err = install_blob(worktree, ondisk_path, path2,
 		    mode2, GOT_DEFAULT_FILE_MODE, blob2,
 		    restoring_missing_file, reverting_versioned_file, 0,
-		    path_is_unversioned, NULL, repo,
+		    path_is_unversioned, 1, NULL, repo,
 		    progress_cb, progress_arg);
 	}
 	if (err)
@@ -5365,7 +5366,7 @@ revert_file(void *arg, unsigned char status, unsigned 
 				    ie->path,
 				    te ? te->mode : GOT_DEFAULT_FILE_MODE,
 				    got_fileindex_perms_to_st(ie), blob,
-				    0, 1, 0, 0, NULL, a->repo,
+				    0, 1, 0, 0, 0, NULL, a->repo,
 				    a->progress_cb, a->progress_arg);
 				if (err != NULL)
 					goto done;
@@ -5416,7 +5417,7 @@ revert_file(void *arg, unsigned char status, unsigned 
 				    ie->path,
 				    te ? te->mode : GOT_DEFAULT_FILE_MODE,
 				    got_fileindex_perms_to_st(ie), blob,
-				    0, 1, 0, 0, NULL, a->repo,
+				    0, 1, 0, 0, 0, NULL, a->repo,
 				    a->progress_cb, a->progress_arg);
 			}
 			if (err)
blob - 58e4c5a5feb8efbbaf0a92292d16bebb8550a104c3684fdf0cb988193bc25100
blob + 1b8cafb150d29d21977dbeade092126d3faf9cd0be8966361094b6d2a92274d0
--- regress/cmdline/histedit.sh	
+++ regress/cmdline/histedit.sh	
@@ -2994,6 +2994,65 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_histedit_added_file() {
+	local testroot=`test_init histedit_added_file`
+	local orig_commit=`git_show_head $testroot/repo`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got checkout failed unexpectedly"
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo new > $testroot/wt/new
+	(cd $testroot/wt && got add new > /dev/null)
+
+	(cd $testroot/wt && got commit -m 'add new file' \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got commit failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	local commit2=`git_show_head $testroot/repo`
+
+	(cd $testroot/wt && got up -q -c $orig_commit > /dev/null)
+
+	# Place an unversioned file into the work tree where the new
+	# file was added. This triggered a bug where histedit would
+	# assume the file was already present in earlier commits and then
+	# treat the commit which actually adds this file as a no-op change.
+	# This test then failed with:
+	# -2f81c7988242 -> c53428a3640e: add new file
+	# +2f81c7988242 -> no-op change: add new file
+	echo new > $testroot/wt/new
+
+	(cd $testroot/wt && got histedit -f > $testroot/stdout)
+	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
+
+	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
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_histedit_no_op
 run_test test_histedit_swap
@@ -3024,3 +3083,4 @@ run_test test_histedit_drop_only
 run_test test_histedit_conflict_revert
 run_test test_histedit_no_eof_newline
 run_test test_histedit_preserve_bad_link
+run_test test_histedit_added_file