Skip to content

Conversation

@redsun82
Copy link
Contributor

@redsun82 redsun82 commented Jan 21, 2025

This adds a --refetch option that makes fetch refetch objects that are already present locally. This can be useful especially in combination with the --dry-run option to see what is fetchable regardless of the current local status, or with --json from #5974 (which this is built on top of) to get download information.

@chrisd8088
Copy link
Member

I usually avoid commenting on draft PRs, since I know folks don't always appreciate comments on work-in-progress, so I'll keep this brief!

I just happened to notice that in the final commit here, which builds on the work from PR #5973, there's a mention in one comment of an option named --refetch rather than --force, and that prompted me to go re-read the Git documentation and realize that you're really onto something there.

The git fetch command's --refetch option is actually the one whose functionality is closest to what this PR implements, so let's call the new option --refetch rather than --force. That's a much better idea, since it keeps the two commands in closer alignment than my proposal.

Apologies for steering you in the wrong direction there, and thanks for spotting the inconsistency!

@redsun82
Copy link
Contributor Author

I usually avoid commenting on draft PRs, since I know folks don't always appreciate comments on work-in-progress, so I'll keep this brief!

I just happened to notice that in the final commit here, which builds on the work from PR #5973, there's a mention in one comment of an option named --refetch rather than --force, and that prompted me to go re-read the Git documentation and realize that you're really onto something there.

The git fetch command's --refetch option is actually the one whose functionality is closest to what this PR implements, so let's call the new option --refetch rather than --force. That's a much better idea, since it keeps the two commands in closer alignment than my proposal.

Apologies for steering you in the wrong direction there, and thanks for spotting the inconsistency!

ah, thanks a lot for this comment! Yeah, I think I hesitated between --force and --refetch and that comment captured that. Once I'll have some more time to get back to this I'll go for --refetch then, I agree with you that it's better!

@redsun82 redsun82 changed the title Add --force option to fetch Add --refetch option to fetch Feb 18, 2025
@redsun82 redsun82 marked this pull request as ready for review February 26, 2025 08:38
@redsun82 redsun82 requested a review from a team as a code owner February 26, 2025 08:38
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thank you again for all the work on these PRs! This one also looks great.

I had a few suggestions here and there, but nothing at all significant.

Thank you again so much for writing up a proposal in #5888 and seeing it through to completion. We sincerely appreciate the help in developing new features for Git LFS!

t/t-fetch.sh Outdated
end_test


begin_test "fetch (empty file)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While experimenting with the new tests in this PR, I discovered (as you may have already!) that the new fetch --refetch with remote and branches test you've added validates the behaviour of the --refetch option with empty files, namely that it correctly ignores them.

I was a bit surprised to realize, though, that the reason this occurs is solely due to the ordering of these tests. If the new p.Size == 0 conditional is removed from the pointers()/pointersToFetch() function in the Go code, the test fails, as we would expect ... but only if the test is located after the existing fetch (empty file) test. That's because the fetch (empty file) test adds an empty file to the Git repository which is shared by many of the tests in the t/t-fetch.sh script.

(Reusing a test repository between tests is not really a practice we follow any more, but the origins of the current t/t-fetch.sh script go back a long way.)

If we were ever to reorder the tests, we might silently lose the validation of the --refetch option's behaviour with regard to empty files; the test would continue to pass, even if we subsequently changed the implementation of the command such that we accidentally disabled the code which skips empty files when re-fetching.

That's a bit unlikely, I admit, but to be on the safe side, would you be willing to add a comment here along the lines of the following?

Suggested change
begin_test "fetch (empty file)"
# NOTE: Do not reorder this test below the subsequent tests, as they depend on
# the empty file it creates in the shared test repository.
begin_test "fetch (empty file)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was how I was made aware of the empty file special case. Your comment about test reordering makes a lot of sense!

I'm applying your suggestion for now, but maybe another approach would be to just add the empty file up in the init for fetch tests test, and remove this test altogether? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and did that in its own commit, I can revert that if you don't think it's a good idea 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, that works too and means we test the empty file case in all the interdependent tests, which is great.

@redsun82 redsun82 requested a review from chrisd8088 March 4, 2025 09:00
@chrisd8088 chrisd8088 merged commit 2d5c3af into git-lfs:main Mar 4, 2025
10 checks passed
@redsun82 redsun82 deleted the fetch-force branch March 10, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants