Skip to content

Conversation

@lukemassa
Copy link
Contributor

@lukemassa lukemassa commented Oct 17, 2025

what

If you go to run Clone() and you find the repo already exists but is not on the right ref, use git to get it to the right ref instead of doing a full re-clone.

why

Right now, when WorkingDir.Clone() is called, if the dir exists, it first checks to see if the ref the repo is on matches the one already determined by the relevant VCS's API as Head. If it's not, we do a forceClone, which deletes the directory and clones from scratch.

However, we know what ref we're trying to get to, so we should be able to use git fetch && git reset --hard to simply move there.

This should be a dramatic speedup, since we already likely have most of the git objects we need on disk. Additionally this is happening while holding a clone lock, so this should reduce contention.

tests

I ran it locally and confirmed that I added a commit to a branch and it didn't blow away the directory. I also added a unit test.

references

Is similar to #2921, but is not quite so ambitious.

@lukemassa lukemassa force-pushed the do_not_delete_dir_on_update branch from 667863e to acf0d9c Compare October 17, 2025 23:27
@lukemassa lukemassa marked this pull request as ready for review October 22, 2025 03:29
@github-actions github-actions bot added the go Pull requests that update Go code label Oct 22, 2025
@dosubot dosubot bot added the feature New functionality/enhancement label Oct 22, 2025
@lukemassa lukemassa force-pushed the do_not_delete_dir_on_update branch from 2395f5a to d7aab6b Compare October 23, 2025 03:20
@lukemassa lukemassa marked this pull request as draft October 23, 2025 23:03
@lukemassa lukemassa marked this pull request as ready for review October 24, 2025 03:01
Signed-off-by: Luke Massa <lmassa@tripadvisor.com>
@lukemassa lukemassa force-pushed the do_not_delete_dir_on_update branch from 65ebdbf to 5c85b4c Compare October 24, 2025 03:38
@lukemassa lukemassa marked this pull request as draft October 25, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functionality/enhancement go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant