Skip to content

Submodule Changes not Being Discarded #4592

Closed

Description

@say25

Description

Submodule Changes not being discarded.

Version

  • GitHub Desktop: 1.1.2-beta4
  • Operating system: macOS Sierra

Steps to Reproduce

  1. Clone GitHub Desktop Repo
  2. Make a change in the Gemoji folder
  3. Attempt to discard the changes.

Expected Behavior

Changes to discard.

Actual Behavior

Nothing.

Logs

2018-05-03.desktop.beta.log

Activity

  1. shiftkey commented on May 3, 2018

    @shiftkey
    Member

    @say25 thanks for the report. It looks like the app isn't able to resolve the submodules listed in the repository, because git-submodule is generating a segmentation fault.

    2018-05-03T05:41:28.688Z - error: [ui] `git submodule status --` exited with an unexpected code: 139.
     fe965f16f6f690d40a738e75a46fad3f41f5daa3 app/static/common/choosealicense.com (fe965f1)
     690a433b668348c33087d34fafe2155ebe8bb4cf app/static/common/gitignore (remotes/origin/reduce-noise-1009-g690a433)
    
    /Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git-submodule: line 979: 12490 Segmentation fault: 11  git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} "$@"
    

    We last updated dugite in 1.1.2-beta2 but I tested the same steps provided in the same build and was able to successfully discard. git-submodule is just a loose script that hasn't changed since January, so I'm puzzled why it's now failing on your setup.

  2. added
    more-info-needed
    on May 3, 2018
  3. shiftkey commented on May 24, 2018

    @shiftkey
    Member

    @say25 I'm still puzzled about how this might be failing. Has it been consistent to reproduce? Any clues about your setup?

  4. say25 commented on May 25, 2018

    @say25
    MemberAuthor

    Tried it on the latest beta, here is my the log from the work flow. I can consistently reproduce it.

    Steps to Reproduce:

    1. Clone GitHub Desktop Repo
    2. Modify Gemoji/Readme.md in any way. (add a space or word at the end of the file for example)
    3. Attempt to discard the changes from the "Changes" page by either right click discarding on
      the Gemoji submodule or the discard all.

    Notice it fails to discard or move anything to the trash.

    2018-05-25T03:19:54.424Z - info: [ui] [AppStore] loading 12 repositories from store
    2018-05-25T03:19:54.426Z - info: [ui] [AppStore] found account: say25 (Steven Yeh)
    2018-05-25T03:19:54.904Z - info: [ui] launching: 1.2.1-beta0 (Mac OS 10.12.6)
    2018-05-25T03:19:54.905Z - info: [ui] execPath: '/Applications/GitHub Desktop.app/Contents/Frameworks/GitHub Desktop Helper.app/Contents/MacOS/GitHub Desktop Helper'
    2018-05-25T03:19:57.792Z - info: [ui] [AppStore.withAuthenticatingUser] account found for repository: desktop - say25 (has token)
    2018-05-25T03:19:58.743Z - info: [ui] [AppStore.withAuthenticatingUser] account found for repository: desktop - say25 (has token)
    2018-05-25T03:20:00.259Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune upstream (took 1.003s)
    2018-05-25T03:31:14.351Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune upstream (took 1.151s)
    2018-05-25T03:32:56.612Z - info: [ui] [AppStore.withAuthenticatingUser] account found for repository: desktop - say25 (has token)
    2018-05-25T03:33:00.229Z - info: [ui] Executing push: git -c credential.helper= push origin master:master --progress (took 3.604s)
    2018-05-25T03:33:41.384Z - error: [ui] Could not load new contents for syntax highlighting
    Error: EISDIR: illegal operation on a directory, read
    2018-05-25T03:33:41.688Z - error: [ui] 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.s.on (/webpack:/app/src/lib/git/spawn.ts:88:15)
        at emitTwo (events.js:125:13)
        at ChildProcess.emit (events.js:213:7)
        at maybeClose (internal/child_process.js:921:16)
        at Socket.stream.socket.on (internal/child_process.js:348:11)
        at emitOne (events.js:115:13)
        at Socket.emit (events.js:210:7)
        at Pipe._handle.close [as _onclose] (net.js:549:12)
    
  5. added
    investigation-needed
    and removed
    more-info-needed
    on May 25, 2018
  6. tierninho commented on Sep 20, 2018

    @tierninho
    Contributor

    This is reproducible for me. Here are my logs:

    Executing listSubmodules: git submodule status --
    install.ts:35 Executing getIndexChanges: git diff-index --cached --name-status --no-renames -z HEAD --
    install.ts:35 Executing updateSubmodule: git submodule update --recursive -- gemoji
    install.ts:35 Executing checkoutIndex: git checkout-index -f -u -q --stdin -z
    install.ts:35 Executing getStatus: git --no-optional-locks status --untracked-files=all --branch --porcelain=2 -z
    install.ts:35 Executing getWorkingDirectoryDiff: git diff HEAD --no-ext-diff --patch-with-raw -z --no-color -- gemoji
    install.ts:35 Executing getBranches: git for-each-ref --format=%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(author)%00%(committer)%00%(parent)%00%(symref)%00%(subject)%00%(body)%00%(trailers:unfold,only)%00%1F refs/heads refs/remotes
    install.ts:35 Executing getRecentBranches: git log -g --no-abbrev-commit --pretty=oneline HEAD -n 2500 --
    install.ts:35 Executing getConfigValueInPath: git config -z trailer.separators
    install.ts:35 Executing getCommits: git log origin/master..master --date=raw --max-count=100 --pretty=%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 --
    install.ts:35 Executing getRemotes: git remote -v
    install.ts:35 Executing getAuthorIdentity: git var GIT_AUTHOR_IDENT
    install.ts:35 [AppStore] initializing compare state
    install.ts:35 Executing getCommits: git log HEAD --date=raw --max-count=100 --pretty=%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 --
    install.ts:35 Executing getStatus: git --no-optional-locks status --untracked-files=all --branch --porcelain=2 -z
    install.ts:35 Executing getConfigValueInPath: git config -z trailer.separators
    install.ts:35 Executing getRemotes: git remote -v
    install.ts:35 Skipping background fetch as 'desktop/desktop' was fetched 73s ago
    

    When trying to commit the change instead, I get:
    screen shot 2018-09-20 at 9 46 09 am

    Git status:

    ➜  desktop git:(master) git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
      (commit or discard the untracked or modified content in submodules)
    
    	modified:   gemoji (untracked content)
    
    no changes added to commit (use "git add" and/or "git commit -a")
    ➜  desktop git:(master)
    

    Git diff:

    /Users/tierninho/bin/gitdiffwrapper.sh: line 2: kdiff3: command not found
    fatal: external diff died, stopping at gemoji
    (END)
    

    And if trying to discard as part of a group of changes, this showed up:
    screen shot 2018-09-20 at 3 16 53 pm

    1.4.1-beta0, mac

  7. added
    bug
    priority-2
    and removed
    investigation-needed
    on Oct 1, 2018
  8. varkor commented on Mar 26, 2019

    @varkor

    This also consistently fails for me (discarding submodule changes has no effect and doesn't raise an error). I'm running GitHub Desktop 1.6.5 on macOS 10.12.6.

  9. tierninho commented on Jun 28, 2019

    @tierninho
    Contributor

    Ran into this again on 2.1.0-beta3: A submodule in the Changes list cannot be discarded.

    When selecting discard all for the file/folder, the dialogue just hangs forever and I have to force close the app to resolve. Not ideal.

    On Windows only. No Logs.

  10. outofambit commented on Aug 21, 2019

    @outofambit
    Contributor

    Proposed approach:

    public async discardChanges(
    files: ReadonlyArray<WorkingDirectoryFileChange>
    ): Promise<void> {
    const pathsToCheckout = new Array<string>()
    const pathsToReset = new Array<string>()
    const submodules = await listSubmodules(this.repository)
    await queueWorkHigh(files, async file => {
    const foundSubmodule = submodules.some(s => s.path === file.path)
    if (file.status.kind !== AppFileStatusKind.Deleted && !foundSubmodule) {
    // N.B. moveItemToTrash is synchronous can take a fair bit of time
    // which is why we're running it inside this work queue that spreads
    // out the calls across as many animation frames as it needs to.
    this.shell.moveItemToTrash(
    Path.resolve(this.repository.path, file.path)
    )
    }
    if (
    file.status.kind === AppFileStatusKind.Copied ||
    file.status.kind === AppFileStatusKind.Renamed
    ) {
    // file.path is the "destination" or "new" file in a copy or rename.
    // we've already deleted it so all we need to do is make sure the
    // index forgets about it.
    pathsToReset.push(file.path)
    // checkout the old path too
    pathsToCheckout.push(file.status.oldPath)
    pathsToReset.push(file.status.oldPath)
    } else {
    pathsToCheckout.push(file.path)
    pathsToReset.push(file.path)
    }
    })
    // Check the index to see which files actually have changes there as compared to HEAD
    const changedFilesInIndex = await getIndexChanges(this.repository)
    // Only reset paths if they have changes in the index
    const necessaryPathsToReset = pathsToReset.filter(x =>
    changedFilesInIndex.has(x)
    )
    const submodulePaths = pathsToCheckout.filter(p =>
    submodules.find(s => s.path === p)
    )
    // Don't attempt to checkout files that are submodules or don't exist in the index after our reset
    const necessaryPathsToCheckout = pathsToCheckout.filter(
    x =>
    submodulePaths.indexOf(x) === -1 ||
    changedFilesInIndex.get(x) !== IndexStatus.Added
    )
    // We're trying to not invoke git linearly with the number of files to discard
    // so we're doing our discards in three conceptual steps.
    //
    // 1. Figure out what the index thinks has changed as compared to the previous
    // commit. For users who exclusive interact with Git using Desktop this will
    // almost always empty which, as it turns out, is great for us.
    //
    // 2. Figure out if any of the files that we've been asked to discard are changed
    // in the index and if so, reset them such that the index is set up just as
    // the previous commit for the paths we're discarding.
    //
    // 3. Checkout all the files that we've discarded that existed in the previous
    // commit from the index.
    await this.performFailableOperation(async () => {
    await resetSubmodulePaths(this.repository, submodulePaths)
    await resetPaths(
    this.repository,
    GitResetMode.Mixed,
    'HEAD',
    necessaryPathsToReset
    )
    await checkoutIndex(this.repository, necessaryPathsToCheckout)
    })
    }
    is the code to start with

    it looks like

    export async function resetSubmodulePaths(
    repository: Repository,
    paths: ReadonlyArray<string>
    ): Promise<void> {
    for (const path of paths) {
    await git(
    ['submodule', 'update', '--recursive', '--', path],
    repository.path,
    'updateSubmodule'
    )
    }
    }

    should be handling this case, but clearly isn't. maybe there's a step we're missing in the discard submodules steps? or we're not properly handling an error? the trick is debugging this code to see where we're missing something.

    also, there are some helpful notes about how discard changes works in desktop at https://github.com/desktop/desktop/blob/development/docs/technical/discard-changes.md

  11. self-assigned this
    on Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpriority-2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions