Checkout fails to discard submodule changes

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Medium
    • None
    • Affects Version/s: 3.4.25
    • Component/s: branch, General
    • None
    • Severity 2 - Major

      Checking out another branch fails to discard changes in submodule(s).

      'Perform submodule actions recursively' option is enabled in Tools > Options > Git tab.

      Repository has at least one submodule repository (our main repo has submodules nested 3 deep:

      Repo A
        Submodule 1 (Repo B)
          Submodule 2 (Repo C)
            Submodule 3 (Repo D)

      Steps to reproduce:

      1. Checkout a branch.
      2. Modify at least one file in the current repository and at least one file in each submodule repository.
      3. Switch to another branch in the main repo.  When the Confirm Branch Switch dialog is displayed (Are you sure you want to switch your working copy to the branch 'xxxx'?), check the option "Clean (discard all changes)".

      Results:

      Changes are discarded in the main repo, branch changed as expected.  Submodule repo changes are not discarded, overall checkout fails.  Submodules remain at the old commit.

      Cause

      When performing submodule actions recursively, the submodule git command does not receive the option to discard changes that was used on the main repo.

      Example command line output:

      git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks reset -q --hard HEAD --
       
      git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks checkout BRANCH_NAME --progress
      M SUBMODULE_1_NAME
      Your branch is up to date with 'origin/BRANCH_NAME'.
       
      Switched to branch 'BRANCH_NAME'
       
      git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks submodule update --init --recursive
      error: Your local changes to the following files would be overwritten by checkout:
      MODIFIED_FILE_NAME(s)
      Please commit your changes or stash them before you switch branches.
       
      Aborting
      fatal: Unable to checkout 'SUBMODULE_1_COMMIT_SHA' in submodule path 'SUBMODULE_1_NAME'
       
      Completed with errors, see above.
       

       

            Assignee:
            Unassigned
            Reporter:
            Kris DeMuth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: