Commit 72fd46fa56e8a73262ff8901b7c93554b7bad3e6

Stefan Sperling 2019-09-06T17:11:26

fix modified files not shown by 'got status' after committing staged changes

diff --git a/lib/worktree.c b/lib/worktree.c
index 71909fd..b6130cb 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3918,7 +3918,8 @@ done:
 
 static const struct got_error *
 update_fileindex_after_commit(struct got_pathlist_head *commitable_paths,
-    struct got_object_id *new_base_commit_id, struct got_fileindex *fileindex)
+    struct got_object_id *new_base_commit_id, struct got_fileindex *fileindex,
+    int have_staged_files)
 {
 	const struct got_error *err = NULL;
 	struct got_pathlist_entry *pe;
@@ -3939,11 +3940,13 @@ update_fileindex_after_commit(struct got_pathlist_head *commitable_paths,
 				    GOT_FILEIDX_STAGE_NONE);
 				err = got_fileindex_entry_update(ie,
 				    ct->ondisk_path, ct->staged_blob_id->sha1,
-				    new_base_commit_id->sha1, 1);
+				    new_base_commit_id->sha1,
+				    !have_staged_files);
 			} else
 				err = got_fileindex_entry_update(ie,
 				    ct->ondisk_path, ct->blob_id->sha1,
-				    new_base_commit_id->sha1, 1);
+				    new_base_commit_id->sha1,
+				    !have_staged_files);
 		} else {
 			err = got_fileindex_entry_alloc(&ie,
 			    ct->ondisk_path, pe->path, ct->blob_id->sha1,
@@ -4282,7 +4285,7 @@ got_worktree_commit(struct got_object_id **new_commit_id,
 		goto done;
 
 	err = update_fileindex_after_commit(&commitable_paths, *new_commit_id,
-	    fileindex);
+	    fileindex, have_staged_files);
 	sync_err = sync_fileindex(fileindex, fileindex_path);
 	if (sync_err && err == NULL)
 		err = sync_err;
@@ -4860,7 +4863,7 @@ rebase_commit(struct got_object_id **new_commit_id,
 		goto done;
 
 	err = update_fileindex_after_commit(&commitable_paths, *new_commit_id,
-	    fileindex);
+	    fileindex, 0);
 	sync_err = sync_fileindex(fileindex, fileindex_path);
 	if (sync_err && err == NULL)
 		err = sync_err;
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index abe3641..c847136 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -1382,8 +1382,10 @@ function test_stage_commit {
 		return 1
 	fi
 
-	echo 'A  epsilon/new' > $testroot/stdout.expected
+	echo 'M  alpha' > $testroot/stdout.expected
+	echo 'A  epsilon/new' >> $testroot/stdout.expected
 	echo 'D  epsilon/zeta' >> $testroot/stdout.expected
+	echo 'M  foo' >> $testroot/stdout.expected
 	echo 'M  gamma/delta' >> $testroot/stdout.expected
 
 	(cd $testroot/wt && got status > $testroot/stdout)