You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
git lfs push <remote> <ref> has poor behavior when tag and branch share a name #1100
I don't think users can actually hit this directly, so I'm mostly filing this for completeness. #1096, #1056, and #1079 are related, and deal with a situation where a branch (like master) has the same name as a file in the working copy. Users can hit those cases, but #1096 should always resolve them because they are straightforward to disambiguate.
A more subtle case is when a where a branch has the same name as a tag instead of the same name as a file. Setup is roughly:
Check out a branch.
Track, add, and commit some LFS stuff.
Tag anything with a tag that has the same name as the branch.
Run git lfs push origin <branch>.
When you run git push in a similar scenario, it stops you immediately because the ref name is ambiguous:
$ GIT_TRACE=1 git push origin branch-and-tag
07:32:46.028980 git.c:348 trace: built-in: git 'push' 'origin' 'branch-and-tag'
error: src refspec branch-and-tag matches more than one.
error: failed to push some refs to '[email protected]:epriestley/poems.git'
However, when you run git lfs push origin master, it runs "successfully" but with the wrong behavior:
Thanks for the detailed report. This seems to be a consequence of using go channels for the scanner (#633). Channels seem like a good way to scan a large history for LFS objects in git blobs asynchronously. I think adding some kind of error channel will make it a lot more complicated. I'd like to explore the following:
Create an actual scanner struct that manages the life cycle of the scanner, giving it the ability to hide the channels implementation and return early with a descriptive error. LFS does this now with the TransferQueue.
Possibly look into using just goroutines and callback functions and dropping channels completely.
I wonder if this could be a source of the case where a git push completes but LFS objects end up missing on the remote? I suspect the behaviour could be similar in pre-push? If so figuring this out is a major win because we get occasional reports of this but haven't got the context of why & can never reproduce it (although this may not be the only case of it).
(edit) oh, I see that's exactly what the linked issue #1056 is about.
I've got a minimal suggestion for addressing this without majorly changing the way the scanners work. I don't think we can use a completely autonomous wrapper like TransferQueue because the scan functions are not generic, and also each client wants to process the scanned items potentially differently, the flexibility of a channel can't really be beaten for that (callbacks would require mutexes etc). How about this:
typeScannerWrapperstruct {
Pointerschan*WrappedPointererrorChanchanerror
}
// Construct a new channel wrapper// arguments are designed to be direct result of scanner funcs e.g.// s, err := NewScannerWrapper(ScanUnpushed(true))// s, err := NewScannerWrapper(ScanRefs(left, right, opts))// Takes return vals of internal scan funcs not func itself, to allow diff input argument signatures// Caller can use s.Pointers directly for normal processing then call Wait() to finish & check for errorsfuncNewScannerWrapper(pointerChanchan*WrappedPointer, errorChanchanerror, errerror) (*ScannerWrapper, error) {
// err is wrapped for convenienceiferr!=nil {
returnnil, err
}
return&ScannerWrapper{pointerChan, errorChan}
}
func (s*ScannerWrapper) Wait() error {
varerrerrorfore:=ranges.errorChan {
iferr!=nil {
// Wrap / append in case multiple errors?
} else {
err=e
}
}
returnerr
}
// Example usage:funcExampleUsage() {
s, err:=NewScannerWrapper(ScanRefs(left, right, opts))
iferr!=nil {
returnerr
}
forp:=ranges.Pointers {
numPointers++
}
// This detects errors during async e.g. at end of git callerr=s.Wait()
iferr!=nil {
returnerr
}
}
All that needs doing apart from this is that all the scan functions should return an error channel as well, which they populate with any failures at the end of the git call, but can keep their own individual argument signatures. This means it's reusable for lots of scan cases but hides the exception case of the error channel in an easier form, without having very much code impact. Thoughts?
(note: code is for illustration, it wont' compile, just threw it together at EOD 😄 )
I'm finding that more rigorous error checking is exposing some other issues, such as lack of detail in git error reporting e.g. exit code 128 - which I've addressed by reporting git's stderr in more detail. Also I discovered we were relying on ignoring the result code of git diff-index in the fsck command; once I started checking the result codes exhaustively fsck stopped working because when corrupted, the clean filter whcih is called by git diff-index as part of the fsck process fails (correctly), which bubbles up and then fails the scan portion of fsck before it gets time to go through the results itself. For now I've just ignored the result code of diff-index in all cases, which is nasty, but I don't know how else to handle this except adding "don't check result codes" arguments or checking for particular error text (which itself is hard because it's 3 levels down from fsck in utility functions and early-outs on error - ergh)
Interestingly my test for your case above doesn't pass even though I'm checking all the result codes now, and it's because git rev-list actually doesn't fail in the ambiguous branch case, it simply displays a warning in the output. It still returns a 0 result code. :/
I had to special-case the ambiguous warning from git rev-list's stderr & promote it to a fatal error, which I assume is what git push does under the hood.
Thanks so much for digging into this 🤘 I tend to start PRs that fix issues like this with the text "Fixes #1100". This will close the issue report when the pull request is merged. I'm not going to re-open this or anything like that. Just FYI.
Cool - I started the description of the PR with "Fixes #1100", is that enough to trigger the magic on merge? I'll know in future I don't have to close manually.
Activity
technoweenie commentedon Mar 28, 2016
Thanks for the detailed report. This seems to be a consequence of using go channels for the scanner (#633). Channels seem like a good way to scan a large history for LFS objects in git blobs asynchronously. I think adding some kind of error channel will make it a lot more complicated. I'd like to explore the following:
sinbad commentedon Mar 30, 2016
I wonder if this could be a source of the case where a
git pushcompletes but LFS objects end up missing on the remote? I suspect the behaviour could be similar inpre-push? If so figuring this out is a major win because we get occasional reports of this but haven't got the context of why & can never reproduce it (although this may not be the only case of it).(edit) oh, I see that's exactly what the linked issue #1056 is about.
sinbad commentedon Mar 30, 2016
I've got a minimal suggestion for addressing this without majorly changing the way the scanners work. I don't think we can use a completely autonomous wrapper like TransferQueue because the scan functions are not generic, and also each client wants to process the scanned items potentially differently, the flexibility of a channel can't really be beaten for that (callbacks would require mutexes etc). How about this:
All that needs doing apart from this is that all the scan functions should return an error channel as well, which they populate with any failures at the end of the git call, but can keep their own individual argument signatures. This means it's reusable for lots of scan cases but hides the exception case of the error channel in an easier form, without having very much code impact. Thoughts?
(note: code is for illustration, it wont' compile, just threw it together at EOD 😄 )
sinbad commentedon Mar 31, 2016
Slept on it and came up with a derived approach which is simpler & more flexible than the above, working on it more & will submit as PR.
sinbad commentedon Mar 31, 2016
My working branch: https://github.com/github/git-lfs/commits/scanner-async-errors
I'm finding that more rigorous error checking is exposing some other issues, such as lack of detail in git error reporting e.g.
exit code 128- which I've addressed by reporting git's stderr in more detail. Also I discovered we were relying on ignoring the result code ofgit diff-indexin thefsckcommand; once I started checking the result codes exhaustivelyfsckstopped working because when corrupted, the clean filter whcih is called bygit diff-indexas part of thefsckprocess fails (correctly), which bubbles up and then fails the scan portion offsckbefore it gets time to go through the results itself. For now I've just ignored the result code ofdiff-indexin all cases, which is nasty, but I don't know how else to handle this except adding "don't check result codes" arguments or checking for particular error text (which itself is hard because it's 3 levels down fromfsckin utility functions and early-outs on error - ergh)sinbad commentedon Mar 31, 2016
Interestingly my test for your case above doesn't pass even though I'm checking all the result codes now, and it's because
git rev-listactually doesn't fail in the ambiguous branch case, it simply displays a warning in the output. It still returns a 0 result code. :/sinbad commentedon Mar 31, 2016
Done: #1118
I had to special-case the ambiguous warning from
git rev-list's stderr & promote it to a fatal error, which I assume is whatgit pushdoes under the hood.technoweenie commentedon Mar 31, 2016
Thanks so much for digging into this 🤘 I tend to start PRs that fix issues like this with the text "Fixes #1100". This will close the issue report when the pull request is merged. I'm not going to re-open this or anything like that. Just FYI.
Now to review the actual PR :)
sinbad commentedon Apr 1, 2016
Cool - I started the description of the PR with "Fixes #1100", is that enough to trigger the magic on merge? I'll know in future I don't have to close manually.
technoweenie commentedon Apr 11, 2016
Yup. Merging #1134 this morning closed #1132 (comment) too.