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
use IsClean to detect if changes need committing #446
Conversation
Signed-off-by: Jack Evans <j.evans.1310@gmail.com>
@@ -310,10 +308,14 @@ func (g *Client) Commit(info git.Commit, commitOpts ...repository.CommitOption) | |||
|
|||
for file := range status { | |||
_, _ = wt.Add(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I understand why we do this here as well as after calling g.writeFile
in the other for loop but changed as minimal as I could
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that it stages files that were changed at the fs
, whether or not they were passed on via options.Files
.
Please note that line 309
does the same loop as status.IsClean()
:
func (s Status) IsClean() bool {
for _, status := range s {
if status.Worktree != Unmodified || status.Staging != Unmodified {
return false
}
}
return true
}
So to avoid going through twice over the statuses, we could just add the if status.Worktree != Unmodified || status.Staging != Unmodified
in 310
here. However, as I mentioned on the other comment, this does not seem to be the problem, as by default go-git
should not allow "empty commits".
@jack-evans thanks for catching this issue and raising this PR, but i'm not sure that this is the fix we need. |
No problem! I was pretty sure when I wrote this there would be a better fix as I don't have a lot of knowledge in this area 😊 |
@aryan9600 I am not sure 80ff3d5 is the culprit, as re-staging unmodified files should not yield a new commit specially after go-git/go-git@a513415. It should behave as the CLI: But given that it wasn't the final fix for fluxcd/image-automation-controller#466, we should be OK to revert it if it fixes the new cli issue. @jack-evans can you test whether reverting the commit above fixes the issue you are experiencing please? |
@pjbgf i reverted the commit and after manually testing, i can confirm it works |
@aryan9600 beat me too it! 🙂 Just tested as well and confirmed the same. I'll close this Pr in favour of the revert! |
Signed-off-by: Jack Evans j.evans.1310@gmail.com
related to fluxcd/flux2#3467. Changed will only be false if options.Files is nil or an empty map, this uses the
IsClean
function on the status to determine if there are actually any changes to the files.I build this locally into the flux2 CLI...
first run was to set the flux version to v0.0.0-dev:
second run correctly didnt push any commits: