Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fetching/checkouts of non-branch/-tag git refs #322

Merged
merged 3 commits into from
Aug 2, 2019

Conversation

marxarelli
Copy link
Contributor

Provides a source.git.ref field for specifying a specific non-branch
non-tag git ref at which to perform a checkout. Providing one will
result in a shallow (depth 1) clone of the repo and shallow subsequent
fetches.

The motivation for this change is to support sourcing of trigger
templates from Gerrit patchsets. Gerrit uses non-branch/-tag refs
extensively and specifically in this case stores change patchsets in
refs/changes/[slice]/[change]/[patchset]. While arbitrary refs are
kind of an obscure git feature, there very well may be other git based
systems utilizing them.

Provides a `source.git.ref` field for specifying a specific non-branch
non-tag git ref at which to perform a checkout. Providing one will
result in a shallow (depth 1) clone of the repo and shallow subsequent
fetches.

The motivation for this change is to support sourcing of trigger
templates from Gerrit patchsets. Gerrit uses non-branch/-tag refs
extensively and specifically in this case stores change patchsets in
`refs/changes/[slice]/[change]/[patchset]`. While arbitrary refs are
kind of an obscure git feature, there very well may be other git based
systems utilizing them.
@marxarelli
Copy link
Contributor Author

While I was implementing this change, I was a little confused about these fetchRefSpecs in store/git.go:

var (
	fetchRefSpec = []config.RefSpec{
		"refs/*:refs/*",
		"HEAD:refs/heads/HEAD",
	}
)

Why such an aggressive fetch of refs/*? Doesn't seem necessary if one is wanting a branch/tag (the default fetch git sets up for a remote should cover those) and could potentially pull down lots of extra data. (We have a repo where +100M unnecessary data would be pulled down from non-default refs.)

The second one seems to confuse git by creating an actual branch named HEAD which conflicts with the symbolic ref of the same name. If I connect to the sensor pod and do a git reflog on the cloned repo I get something like "ambiguous reference HEAD." I can create an issue with more info if that helps.

Anyway, since I don't know the history behind those refspecs, I didn't want to touch it, and simply included a conditional exemption for when source.git.ref is supplied. In that case, it really shouldn't be necessary to have anything but the specific ref.

@VaibhavPage VaibhavPage self-requested a review August 2, 2019 01:48
Copy link
Contributor

@VaibhavPage VaibhavPage left a comment

Choose a reason for hiding this comment

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

left a comment, everything else looks good.

pkg/apis/sensor/v1alpha1/types.go Outdated Show resolved Hide resolved
@VaibhavPage VaibhavPage self-requested a review August 2, 2019 15:02
@VaibhavPage VaibhavPage merged commit 6a5a622 into argoproj:master Aug 2, 2019
@marxarelli
Copy link
Contributor Author

Thanks for the merge!

@mgoodness
Copy link
Contributor

mgoodness commented Aug 29, 2019

How can I use this? Built from master, pushed & deployed new images, but source.git.ref isn't recognized as a valid field.

Diff when applying my Sensor via Argo CD:

Screen Shot 2019-08-29 at 1 53 47 PM

It reverts (drops the field) every time I sync.

juliev0 pushed a commit to juliev0/argo-events that referenced this pull request Mar 29, 2022
* Support fetching/checkouts of non-branch/-tag git refs

Provides a `source.git.ref` field for specifying a specific non-branch
non-tag git ref at which to perform a checkout. Providing one will
result in a shallow (depth 1) clone of the repo and shallow subsequent
fetches.

The motivation for this change is to support sourcing of trigger
templates from Gerrit patchsets. Gerrit uses non-branch/-tag refs
extensively and specifically in this case stores change patchsets in
`refs/changes/[slice]/[change]/[patchset]`. While arbitrary refs are
kind of an obscure git feature, there very well may be other git based
systems utilizing them.

* Fixed protobuf field index for Ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants