Fix some “Stage All” special cases#1037
Conversation
(Not always but) repository folders that weren't registered in .gitmodules would cause the method to fail: “libgit2 error (-4): submodule 'submodules/transfer-photo-albums/' has not been added yet”
When addFileInWorkingDirectory encountered an error, it would return YES regardless.
| if (failed && shouldWriteRepository) { | ||
| if (shouldWriteRepository) { | ||
| if (shouldWriteRepository) { | ||
| if (failed) { |
There was a problem hiding this comment.
Hey Nathan (@Cykelero), apologies for taking forever on this. I'm trying to wrap my head around the logic here. Previously if there was any failure we wouldn't write anything, but that's no longer the case. However, the logic in the for loop is to break on a the first failed thing to add.
With the changes made here, is it now more appropriate to continue rather than break (or else statement)?
There was a problem hiding this comment.
No problem for the delay, of course.
I think you're right about it being a better idea to continue—I had carried over a habit from Retcon (as soon as anything goes wrong, it tries to immediately stop touching anything) but that's not a good fit in GUK. Fixed!
(also, I renamed shouldWriteRepository to needsToWriteIndex, for clarity)
Also, rename `shouldWriteRepository` to the more appropriate `needsToWriteIndex`.
| GCSubmodule* submodule = [self lookupSubmoduleWithName:delta.canonicalPath error:error]; | ||
| if (!submodule || ![self addSubmoduleToRepositoryIndex:submodule error:error]) { | ||
| return NO; | ||
| if (![[*error localizedDescription] hasSuffix:@"' has not been added yet"]) { |
There was a problem hiding this comment.
Also, is it possible error is NULL here? If I remember my C-isms well enough, dereferencing a NULL error would crash, no?
There was a problem hiding this comment.
Good catch. I fixed both instances of that bug.
Of note, my fix is a bit too simple: it effectively disables this PR's bugfix, when no error is passed. But, that new bug is niche enough that it should be OK; handling it right would mean more code, and some pointer juggling I'm not completely comfortable with.
This fixes two issues with the Stage All button.
Reproducing
Reproducing the conflict issue:
git pull)Reproducing the submodule issue:
Notes
The fixes look at the error messages to decide what to do—that might not be ideal, but:
-1). That one feels flakier, as Apple could change the error message at any time, and the message could be localized if the app runs in a different language; but in practice, Apple is unlikely to change that message, and GitUp is in English only.