generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 24
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: do not use git set-branches if the target branch is not currently available in the repository #491
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… available in the repository Signed-off-by: Trong Nhan Mai <[email protected]>
185e9df
to
abc8d14
Compare
tromai
commented
Sep 29, 2023
tromai
commented
Sep 29, 2023
behnazh-w
reviewed
Oct 9, 2023
behnazh-w
reviewed
Oct 9, 2023
Signed-off-by: Trong Nhan Mai <[email protected]>
tromai
commented
Oct 13, 2023
behnazh-w
reviewed
Oct 26, 2023
behnazh-w
approved these changes
Oct 26, 2023
art1f1c3R
pushed a commit
that referenced
this pull request
Nov 29, 2024
…y available in the repository (#491) Signed-off-by: Trong Nhan Mai <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #486
Bug description
This bug happened because of the way branch check out is handling in this method.
At the moment, the process Macaron in which Macaron tries to checkout the correct branch and commit for the analysis is as follows:
The branch to checkout is either the value provided by the user (via
--branch
in the CLI) or the default branch of the repository (implementation):git rev-parse --abbrev-ref origin/HEAD
to obtain the valueorigin/<default_branch_name>
(references).Macaron try to check out that branch (implementation here)..
res_branch in [os.path.basename(ref.name) for ref in org_remote.refs]
refs
inorg_remote
instance would returngit.RemoteReference
instances (according to gitpython documentation).git.RemoteReference
can be considered a reference to the latest commit of a remote branch (from the last time we communicate with remote). Therefore,org_remote.refs
will return an iterator of remote references that this local repository currently have (which mean that it could be missing any new remote branches, etc.).org_remote.refs
does not return all available remote branches. It only contains: 1.refs/remotes/origin/<branch_name>
which point to the branch which we shallow clone (if no branch is provided e.g.git clone --depth=1 <url>
), this will berefs/remotes/origin/<default_branch>
. 2. if it's a shallow clone of the default branch, there will be also arefs/remotes/origin/HEAD
.If Macaron cannot find the target branch from
org_remote.refs
, Macaron will try to setup a local branch that track that branch from origin remote (implementation here).The full command is:
git remote set-branches --add origin '<target_branch>'
(references) What this command do is that it setup the branch list to track a branch<target_branch>
from the remote. The--add
will make sure that we only add the new tracked branch into the list of tracked branches. The next time we fetch, git will also try to fetch this branch from the remote repository. The reason I did it this way is to make sure that we only need to fetch the branch that we are interested in when working with shallow clones.This is the command that causes the bug in Repository checkout fails in some cases #486:
.git/config
file in the target repository with<target_branch>
. Therefore, if the branch doesn't exist, subsequent fetching/pulling will always fail because git will try to ask the remote for this non-exist branch and return error everytime.offline_mode
is set or not..git/config
.Solution.
To resolve this bug, I simplify the logic for checkout branch and commit for a target repository with the following goals:
git remote set-branches --add origin '<target_branch>'
check_out_repo_target
method are:git fetch
: happen before checkout branch.git pull --ff-only
before checkout a specific commit.If the checkout operation fails for either branch or commit, we return errors.