commit 4a26d3f877326c99bcf462b076800a112319ff6d from: Stefan Sperling date: Wed Oct 07 22:37:48 2020 UTC fix a bug where 'got status' showed an unchanged empty file as changed commit - 6b36edd809ff151ee866ec81cd007767d76cf778 commit + 4a26d3f877326c99bcf462b076800a112319ff6d blob - d376968700adbabb24ee439230e26f1477711121 blob + 1c36cc66e308756a1e4d87c0e625f934a016272f --- lib/worktree.c +++ lib/worktree.c @@ -1784,12 +1784,12 @@ get_file_status(unsigned char *status, struct stat *sb err = got_error_from_errno("fread"); goto done; } - if (blen == 0) { + if (blen - hdrlen == 0) { if (flen != 0) *status = GOT_STATUS_MODIFY; break; } else if (flen == 0) { - if (blen != 0) + if (blen - hdrlen != 0) *status = GOT_STATUS_MODIFY; break; } else if (blen - hdrlen == flen) { blob - 9aca32fad809caf8f50a0a3171c6f6ac997ce8ef blob + 09bd0ffdb02fad6af784ac9f2d1ab88e0338f86e --- regress/cmdline/status.sh +++ regress/cmdline/status.sh @@ -748,8 +748,61 @@ test_status_status_code() { test_done "$testroot" "$ret" } + +test_status_empty_file() { + local testroot=`test_init status_empty_file` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + return 1 + fi + + echo -n "" > $testroot/wt/empty + (cd $testroot/wt && got add empty >/dev/null) + + echo 'A empty' > $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 + + (cd $testroot/wt && got commit -m "empty file" >/dev/null) + + (cd $testroot/wt && got status > $testroot/stdout) + echo -n > $testroot/stdout.expected + 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 + # update the timestamp; this used to make the file show up as: + # M empty + # which should not happen + touch $testroot/wt/empty + + (cd $testroot/wt && got status > $testroot/stdout) + + echo -n > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_status_basic run_test test_status_subdir_no_mods @@ -766,3 +819,4 @@ run_test test_status_many_paths run_test test_status_cvsignore run_test test_status_gitignore run_test test_status_status_code +run_test test_status_empty_file