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

GitArtifact hardcodes master as the default branch, and there's no mention of this in the documentation #3327

Open
ElectricWarr opened this issue Oct 14, 2024 · 2 comments

Comments

@ElectricWarr
Copy link

ElectricWarr commented Oct 14, 2024

Using a Sensor to trigger creation of some k8s objects pulled directly from a git repo, I expected GitArtifact to take the default branch if source.git.branch parameter was not set, but instead the trigger fails with the following error:

{"level":"error","ts":1728911591.502107,"logger":"argo-events.sensor","caller":"sensors/listener.go:364","msg":"Failed to execute a trigger","sensorName":"mySensor","error":"failed to fetch artifact, failed after retries: failed to checkout. err: reference not found","triggerName":"workflow-trigger-1","stacktrace":"github.com/argoproj/argo-events/sensors.(*SensorContext).triggerActions.func1\n\t/home/runner/work/argo-events/argo-events/sensors/listener.go:364"}

master seems to be hardcoded as the default here. The docs for GitArtifact are here.

Many many projects, especially new repos, use main as their default branch now, and the error is a little opaque to the average user, so it would be nice if it could include the specific reference that wasn't found.

If targeting the default branch isn't possible then I suggest the documentation should include something about how some combination of branch/tag/ref is recommended, and what the behaviour is by default if none are specified.

Edit: I'm aware that default branches are not strictly a git feature, but all the git tools I've ever used behave the same way - when asked to clone a repo from a URL, they always clone the default branch unless explicitly told otherwise.

@ElectricWarr
Copy link
Author

For reference the source block on my k8s trigger template looks like this:

git:
  cloneDirectory: /git/argoproj
  creds:
    password:
      key: password
      name: my-secret
    username:
      key: username
      name: my-secret
  filePath: pipeline.yaml
  url: redacted

@ElectricWarr
Copy link
Author

On a shallow read it looks like where branch, tag and ref are all unset, r.Clone() could be used in place of the current r.Fetch()/w.Checkout() path.

As far as I can see this would be fully backwards-compatible, the only affected users would have to be depending on master being the default for repos where master wasn't actually the default branch of their target remote. I'd expect very few of those exist since it wasn't documented!

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

No branches or pull requests

1 participant