commit fd785a9ac70d88714b1d0533768076bcf5c9c2d2 from: Stefan Sperling date: Wed Apr 12 19:12:37 2023 UTC update the base commit ID of unmodified files if the blob ID matches This avoids having to run 'got update' after operations which run checkout_files() and where a file happens to have the same blob ID but its base commit differs from the commit we are updating to. Found while investigating a bug report by naddy@ ok op, jamsek (earlier version) commit - af21bb7e28a5a337eb50bfd364a1e1640c6f97b1 commit + fd785a9ac70d88714b1d0533768076bcf5c9c2d2 blob - 9e87414b038cb6aa0ef965f162999f1108c5d82a blob + cf84e01c6343a70a2374f95e81c6952c1ce51ad6 --- lib/worktree.c +++ lib/worktree.c @@ -1997,6 +1997,12 @@ update_blob(struct got_worktree *worktree, memcmp(ie->blob_sha1, te->id.sha1, SHA1_DIGEST_LENGTH) == 0) { /* Different commit but the same blob. */ + if (got_fileindex_entry_has_commit(ie)) { + /* Update the base commit ID of this file. */ + memcpy(ie->commit_sha1, + worktree->base_commit_id->sha1, + sizeof(ie->commit_sha1)); + } err = sync_timestamps(worktree->root_fd, path, status, ie, &sb); if (err) blob - 822844175d6069cb0ad59c5bd870b63d886b9990 blob + c08237c6cd1b14453b8e4f8e39789a3c6c017f1c --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -1899,12 +1899,7 @@ test_update_modified_submodules() { (cd $testroot/repo && git add repo2) git_commit $testroot/repo -m "modified submodule link" - # This update only records the new base commit. Otherwise it is a - # no-op change because Got's file index does not track submodules. - echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected - git_show_head $testroot/repo >> $testroot/stdout.expected - echo >> $testroot/stdout.expected - + echo "Already up-to-date" > $testroot/stdout.expected (cd $testroot/wt && got update > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout