Repository navigation
Enable discarding submodule changes - #8218
Conversation
git-submodule(1):
If --force is specified, the submodule will be checked out (using
git checkout --force), even if the commit specified in the index of
the containing repository already matches the commit checked out in
the submodule.
Adding this flag helps discard dirty working files when choosing
the "Discard changes" menu item for submodules.
| 'updateSubmodule' | ||
| ) | ||
| } | ||
| await git( |
There was a problem hiding this comment.
doing this in one shell command is super awesome ✨
👍 on this if its not too time consuming to add. (i'm not sure if we have some repository with submodules fixtures. @vilmibm and i were looking at unit test setup stuff recently so he can probably answer questions about this too.) |
tierninho
left a comment
There was a problem hiding this comment.
Tested this fix and after modifying a file in the Genmoji folder, I spotted this in the console:
install.ts:23 Could not load new contents for syntax highlighting
Error: EISDIR: illegal operation on a directory, read
error @ install.ts:23
(anonymous) @ index.ts:118
Promise.catch (async)
getFileContents @ index.ts:117
initDiffSyntaxMode @ text-diff.tsx:269
componentDidMount @ text-diff.tsx:799
commitLifeCycles @ react-dom.development.js:9784
commitAllLifeCycles @ react-dom.development.js:11455
callCallback @ react-dom.development.js:100
invokeGuardedCallbackDev @ react-dom.development.js:138
invokeGuardedCallback @ react-dom.development.js:187
commitRoot @ react-dom.development.js:11594
completeRoot @ react-dom.development.js:12502
performWorkOnRoot @ react-dom.development.js:12452
performWork @ react-dom.development.js:12370
performSyncWork @ react-dom.development.js:12347
requestWork @ react-dom.development.js:12247
scheduleWorkImpl @ react-dom.development.js:12122
scheduleWork @ react-dom.development.js:12082
enqueueSetState @ react-dom.development.js:6644
module.exports../app/node_modules/react/cjs/react.development.js.Component.setState @ react.development.js:238
(anonymous) @ app.tsx:203
module.exports../app/node_modules/event-kit/lib/emitter.js.module.exports.Emitter.simpleDispatch @ emitter.js:25
module.exports../app/node_modules/event-kit/lib/emitter.js.module.exports.Emitter.emit @ emitter.js:141
emitUpdate @ base-store.ts:34
emitUpdateNow @ app-store.ts:523
(anonymous) @ app-store.ts:515
requestAnimationFrame (async)
emitUpdate @ app-store.ts:514
setAppMenu @ app-store.ts:3939
(anonymous) @ app-store.ts:426
emit @ events.js:194
install.ts:31 Executing getPartialBlobContents: git show HEAD:gemoji (took 0.013s)
install.ts:23 Could not load old contents for syntax highlighting
Error: Git returned an unexpected exit code '128' which should be handled by the caller.'
at ChildProcess.<anonymous> (/Users/tierninho/github/desktop/webpack:/app/src/lib/git/spawn.ts:93:15)
at ChildProcess.emit (events.js:194:13)
at maybeClose (internal/child_process.js:998:16)
at Socket.<anonymous> (internal/child_process.js:403:11)
at Socket.emit (events.js:194:13)
at Pipe.<anonymous> (net.js:593:12)
Some test results:
- ✅ discarding a Genmoji file when the file contents are changed
- ❌ discarding a Genmoji file when the file name is changed
- ✅ discard single file vs discard all files
- ✅ discarding submodule and normal file at same time
I suspect the ❌ is because I changed the name of the file and not the contents. When doing so, the original file is recreated and the user ends up with two files and discarding problems (as well as stashing problems).
Logs while attempting ❌ above:
Executing listSubmodules: git submodule status -- (took 0.162s)
install.ts:31 Executing getIndexChanges: git diff-index --cached --name-status --no-renames -z HEAD -- (took 0.012s)
install.ts:31 Executing updateSubmodule: git submodule update --recursive --force -- gemoji (took 0.198s)
install.ts:31 Executing checkoutIndex: git checkout-index -f -u -q --stdin -z (took 0.011s)
install.ts:31 Executing getStatus: git --no-optional-locks status --untracked-files=all --branch --porcelain=2 -z (took 0.074s)
install.ts:31 Executing getRecentBranches: git log -g --no-abbrev-commit --pretty=oneline HEAD -n 2500 -- (took 0.020s)
install.ts:31 Executing getWorkingDirectoryDiff: git diff HEAD --no-ext-diff --patch-with-raw -z --no-color -- gemoji (took 0.031s)
install.ts:31 Executing getBranches: git for-each-ref --format=%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(objectname:short)%00%(author)%00%(committer)%00%(parent)%00%(symref)%00%(subject)%00%(body)%00%(trailers:unfold,only)%00%1F refs/heads refs/remotes (took 0.041s)
install.ts:31 Executing getConfigValueInPath: git config -z trailer.separators (took 0.010s)
install.ts:31 Executing getCommits: git log origin/development..development --date=raw --max-count=100 --pretty=%H%x1F%h%x1F%s%x1F%b%x1F%an <%ae> %ad%x1F%cn <%ce> %cd%x1F%P%x1F%(trailers:unfold,only) -z --no-show-signature --no-color -- (took 0.032s)
install.ts:31 Executing getAuthorIdentity: git var GIT_AUTHOR_IDENT (took 0.026s)
install.ts:31 Executing getStashEntries: git log -g -z --pretty=%gd%x1F%H%x1F%gs refs/stash (took 0.031s)
install.ts:31 Executing getRemotes: git remote -v (took 0.037s)
install.ts:31 Executing getConfigValueInPath: git config -z pull.rebase (took 0.048s)
install.ts:31 Executing getSymbolicRef: git symbolic-ref -q refs/remotes/origin/HEAD (took 0.053s)
tested build 0db5954, mac
|
quick note on this one:
this is because that being said, this PR is still a marked improvement on the current state of things, so i'd be in favor of merging as-is and filing a new issue for this last case. |
I think we absolutely should consider that but it does seem like this PR improves upon one scenario while not making the trash/restore situation any worse so I still think it's valuable to get this in. I'm gonna open an issue to track this and the fact that discarding a submodule using this method still doesn't clear the dirty state when the submodule contains untracked files. |
we've captured the remaining issues found and are accepting this as it's an improvement

Overview
Fixes #4592
Description
Without
--force,git submodule update -- path/to/submoduleis not enough to discard changes in the working copy under the git submodule since git will see that the currently checked out git commit matches the one that the superproject expects and the operation will be a no-op.Potential TODO:
Release notes
Notes: