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

Fix issue preventing import.git from syncing due to divergent branches #1629

Merged
merged 6 commits into from
Oct 2, 2024

Conversation

ptodev
Copy link
Contributor

@ptodev ptodev commented Sep 6, 2024

PR Description

Consider this situation:

  • import.git is configured to use branch A.
  • Alloy is then stopped, and its new configuration is configured to use branch B.
  • If branches A and B are divergent, import.git will fail to switch to branch B because it's going to try to pull A into B.

The user will get a "failed to update repository \"git@github.com:org/repo.git\": non-fast-forward update" error.

I suppose the same thing could also happen if a force push is done to the branch Alloy is monitoring.

Since Alloy is only reading from the repo, but not writing, there is no point in trying to do a pull. It's much easier to just do a fetch and checkout.

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@ptodev ptodev requested a review from a team as a code owner September 6, 2024 17:22
@ptodev ptodev changed the title Fix issue preventing git.import from syncing due to divergent branches Fix issue preventing import.git from syncing due to divergent branches Sep 6, 2024
@mattdurham
Copy link
Collaborator

I think this was my original approach but it had issues with switching branches and accessing HEAD. Hence the test failing.

@ptodev
Copy link
Contributor Author

ptodev commented Sep 10, 2024

I think this was my original approach but it had issues with switching branches and accessing HEAD. Hence the test failing.

@mattdurham Thank you, I had a look at the Agent PR which introduced pull just now. I think the default value for "revision" shouldn't be something like "HEAD". HEAD refers to the tip of the current branch. But what is the current branch in import.git? :) There is no config attribute to set it, so I'm not sure how it gets chosen. Maybe the remote tells it what the default branch is.

I think we should simply not allow values such as "HEAD", "FETCH_HEAD", etc to be the "revision". I updated my PR accordingly - would you like to take a look please? If you agree with it, I can update the docs and I'll also list it as a breaking change in the changelog.

If a user is able to set "revision" to something like "HEAD", "FETCH_HEAD" etc, then they'd be relying on some internal quirk of how import.git works, which wouldn't be correct.

@mattdurham
Copy link
Collaborator

HEAD isn't a quirk of import.git but fundamental feature for git. That being said I am not against saying you cant use the pointer style aliases and instead have to use a non alias value.

Copy link
Collaborator

@mattdurham mattdurham left a comment

Choose a reason for hiding this comment

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

LGTM, its a breaking change but if this cleans this up totally fine and once the tests pass.

@ptodev ptodev force-pushed the ptodev/bugfix-import-git-divergent branch from 9126f5a to 2ec6dcf Compare September 20, 2024 10:42
@ptodev ptodev force-pushed the ptodev/bugfix-import-git-divergent branch from 2ec6dcf to 3dbe41a Compare October 1, 2024 14:18
@ptodev ptodev merged commit f37a334 into main Oct 2, 2024
18 checks passed
@ptodev ptodev deleted the ptodev/bugfix-import-git-divergent branch October 2, 2024 12:37
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.

2 participants