fix get_file_status() for files larger than blob read buffer size
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
diff --git a/lib/worktree.c b/lib/worktree.c
index 1e6da72..4eccffd 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -900,7 +900,8 @@ get_file_status(unsigned char *status, struct stat *sb,
err = got_object_blob_read_block(&blen, blob);
if (err)
break;
- flen = fread(fbuf, 1, sizeof(fbuf), f);
+ /* Skip length of blob object header first time around. */
+ flen = fread(fbuf, 1, sizeof(fbuf) - hdrlen, f);
if (blen == 0) {
if (flen != 0)
*status = GOT_STATUS_MODIFY;
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index da1fdae..72eb5ce 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -280,6 +280,59 @@ function test_status_ignores_symlink {
test_done "$testroot" "$ret"
}
+function test_status_shows_no_mods_after_complete_merge {
+ local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
+
+ # make this file larger than the usual blob buffer size of 8192
+ echo -n > $testroot/repo/numbers
+ for i in `jot 16384`; do
+ echo "$i" >> $testroot/repo/numbers
+ done
+
+ (cd $testroot/repo && git add numbers)
+ git_commit $testroot/repo -m "added numbers file"
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ sed -i 's/2/22/' $testroot/repo/numbers
+ git_commit $testroot/repo -m "modified line 2"
+
+ sleep 1
+ # modify line 2 again; no local changes are left after merge
+ sed -i 's/2/22/' $testroot/wt/numbers
+
+ echo "G numbers" > $testroot/stdout.expected
+ echo -n "Updated to commit " >> $testroot/stdout.expected
+ git_show_head $testroot/repo >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update > $testroot/stdout)
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo -n > $testroot/stdout.expected
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ cmp $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_status_basic
run_test test_status_subdir_no_mods
run_test test_status_subdir_no_mods2
@@ -287,3 +340,4 @@ run_test test_status_obstructed
run_test test_status_shows_local_mods_after_update
run_test test_status_unversioned_subdirs
run_test test_status_ignores_symlink
+run_test test_status_shows_no_mods_after_complete_merge