make 'got status' indicate changes relative to staged files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/got/got.c b/got/got.c
index dae6672..0cde839 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2368,8 +2368,7 @@ print_status(void *arg, unsigned char status, unsigned char staged_status,
const char *path, struct got_object_id *blob_id,
struct got_object_id *staged_blob_id, struct got_object_id *commit_id)
{
- if (status == staged_status &&
- (status == GOT_STATUS_ADD || status == GOT_STATUS_DELETE))
+ if (status == staged_status && (status == GOT_STATUS_DELETE))
status = GOT_STATUS_NO_CHANGE;
printf("%c%c %s\n", status, staged_status, path);
return NULL;
diff --git a/lib/worktree.c b/lib/worktree.c
index 4b2e439..d402893 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1084,7 +1084,8 @@ get_file_status(unsigned char *status, struct stat *sb,
if (!got_fileindex_entry_has_file_on_disk(ie)) {
*status = GOT_STATUS_DELETE;
return NULL;
- } else if (!got_fileindex_entry_has_blob(ie)) {
+ } else if (!got_fileindex_entry_has_blob(ie) &&
+ staged_status != GOT_STATUS_ADD) {
*status = GOT_STATUS_ADD;
return NULL;
}
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 5aa5444..5bce7df 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -76,8 +76,52 @@ function test_stage_status {
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified file again" >> $testroot/wt/alpha
+ echo "modified added file again" >> $testroot/wt/foo
+
+ echo 'MM alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo 'A epsilon/new' >> $testroot/stdout.expected
+ echo 'M epsilon/zeta' >> $testroot/stdout.expected
+ echo 'MA foo' >> $testroot/stdout.expected
+ echo 'D gamma/delta' >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ # test no-op change of added file with new stat(2) timestamp
+ echo "new file" > $testroot/wt/foo
+ echo ' A foo' > $testroot/stdout.expected
+ (cd $testroot/wt && got status foo > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ # test staged deleted file which is restored on disk
+ echo "new file" > $testroot/wt/beta
+ echo ' D beta' > $testroot/stdout.expected
+ (cd $testroot/wt && got status beta > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
fi
test_done "$testroot" "$ret"
+
}
run_test test_stage_basic