-
Notifications
You must be signed in to change notification settings - Fork 23
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
The reset_git_repo
function fails when HEAD is detached
#530
Comments
The issue can be reproduced in git version 2.25.1 |
I have dig a bit into this issues with the repository opentest4j, which correspond to the PURL Note: I highly recommend reading through this article first to understand about the background of line endinds in git. The history of opentest4jAt 96502f5There is no
At 6ae5b16 - right after commit 96502f5.
At f2c384f3 - right after commit 6ae5b16.The .gitattribute file is committed with the following content.
Therefore when you check out this commit:
Now, if you freshly clone the repository and checkout commit f2c384f3 into the working tree:
This is the same behavior specified in this Github issue.
Why does this happen in the first place?In commit f2c384f3 as I mentioned above, even though the .gitattribute files is added, theses changes won’t take effect immediately for files committed into the repository prior to the commit of .gitattributes. This will mean that gradlew.bat is still stored with line ending crlf in the repository. From my understanding, the eol for gradlew.bat within the repository is crlf, but because This is consistent with the discussion in an existing Stackoverflow thread. One thing I know exactly sure is that the author that made committed the content of .gitattribute in commit f2c384f3 didn't run In later commits:
How can we address this?We can run |
@tromai thanks for looking into the issue. It's still unclear to me why these two files remain modified after calling the reset_git_repo function. Do you have any idea? If we run -f, --force
When switching branches, proceed even if the index or the working tree differs from HEAD, and even if there are untracked files in the way. This is
used to throw away local changes and any untracked files or directories that are in the way.
When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored. So, if we do that, we won't need to |
The root cause of the issue:
Now let's get back to the reset_git_repo function. This function called within Macaron at the moment will try to reset both the index and the working tree of the repository it's analyzing.
Yes this is true. In theory, we wouldn't need to reset at all (given that we have created a stash) before trying to checkout with the Furthermore, for optimization, when Macaron deals with repositories that it caches inside |
Thanks for the clarification.
I don't think we even need to stash if we use |
That's correct. The reason the stash command was used is because we were trying to save any local changes (propably made by the users) to the repository we are analyzing. This is mostly specific for the use case where the user wants to provide a local repository path to Macaron. If we decide that we wouldn't be responsible for losing any local changes in the repository the user want to analyze, we could avoid stashing and put some documentation saying that Macaron could potentially remove any local non-committed changes. |
Sounds good. We should add a note or warning to the docs for local repo use case. |
… (#536) Signed-off-by: Trong Nhan Mai <[email protected]>
… (#536) Signed-off-by: Trong Nhan Mai <[email protected]>
If a repository is cloned by Macaron and then we checkout a commit which makes the
HEAD
detached, if any of the files are modified for some reason, the reset_git_repo function fails tostash
the changes and the second run ofMacaron
on that target fails.Note that supporting commit checkout is crucial for mapping artifacts to commits.
To reproduce the error on the
staging
branch run:The text was updated successfully, but these errors were encountered: