Skip to content

Enable discarding submodule changes - #8218

Merged
niik merged 4 commits into
developmentfrom
discard-changes-submodule
Aug 18, 2020
Merged

niik merged 4 commits into
developmentfrom
discard-changes-submodule

Conversation

@mislav

@mislav mislav commented Sep 5, 2019

Copy link
Copy Markdown
Contributor

Overview

Fixes #4592

Description

Without --force, git submodule update -- path/to/submodule is 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:

  • The current approach discards changes under the submodule without moving the copies of changed files to Trash. Should we consider moving them to Trash to avoid discarding someone's work irrevocably?
  • It might be a good idea to add a test that exercises discarding changes from multiple submodules at the same time.

Release notes

Notes:

  • Enables discarding changes to files under git submodules

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this in one shell command is super awesome ✨

@mislav mislav added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 6, 2019
@outofambit

Copy link
Copy Markdown
Contributor

It might be a good idea to add a test that exercises discarding changes from multiple submodules at the same time.

👍 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
tierninho self-requested a review September 7, 2019 00:08

@tierninho tierninho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Screen Shot 2019-09-06 at 1 48 57 PM

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

@outofambit

Copy link
Copy Markdown
Contributor

quick note on this one:

❌ discarding a Genmoji file when the file name is changed

this is because git submodule update doesn't touch untracked files. not sure what we need to do to cover that case too.

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.

amber888-star
amber888-star approved these changes Oct 1, 2019 •
@niik

niik commented Aug 18, 2020

Copy link
Copy Markdown
Member
  • The current approach discards changes under the submodule without moving the copies of changed files to Trash. Should we consider moving them to Trash to avoid discarding someone's work irrevocably?

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.

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a clear improvement and I've opened #10403 and #10402 to track the remaining work. Thanks so much @mislav!

@niik
niik dismissed tierninho’s stale review August 18, 2020 15:55

we've captured the remaining issues found and are accepting this as it's an improvement

@niik
niik merged commit 1d43293 into development Aug 18, 2020
@niik
niik deleted the discard-changes-submodule branch August 18, 2020 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Submodule Changes not Being Discarded

6 participants