{"thread":{"id":"47116","subject":"Bug report: git reset --hard does not fix submodule worktree","startedAt":"2017-11-04T00:46:34Z","lastAt":"2017-11-06T20:50:49Z","messageCount":2,"participants":["Billy O'Neal (VC LIBS)","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"331812","messageId":"BN6PR21MB0114B8ECD6E8A158FB4A6FBFCB520@BN6PR21MB0114.namprd21.prod.outlook.com","threadId":"47116","inReplyTo":null,"subject":"Bug report: git reset --hard does not fix submodule worktree","fromName":"Billy O'Neal (VC LIBS)","fromEmail":"bion@microsoft.com","sentAt":"2017-11-04T00:46:26Z","receivedAt":"2017-11-04T00:46:34Z","isPatch":false,"sender":{"key":"bion@microsoft.com","avatar":null},"body":"Hello, Git folks. I managed to accidentally break the our test lab by attempting to git mv a directory with a submodule inside. It seems like if a reset does an undo on a mv, the workfold entry should be fixed to put the submodule in its old location. Consider the following sequence of commands:\n\nSetup a git repo with a submodule:\nmkdir metaproject\nmkdir upstream\ncd metaproject\ngit init\ncd ..\\upstream\ngit init\necho hello > test.txt\ngit add -A\ngit commit -m \"an example commit\"\ncd ..\\metapoject\nmkdir start\ngit submodule add ../upstream start/upstream\ngit add -A\ngit commit -m \"Add submodule in start/upstream.\"\n\nMove the directory containing the submodule:\ngit mv start target\ngit add -A\ngit commit -m \"Moved submodule parent directory.\"\n\nCheck that the worktree got correctly fixed by git mv; this output is as expected:\ntype .git\\modules\\start\\upstream\\config\n[core]\n        repositoryformatversion = 0\n        filemode = false\n        bare = false\n        logallrefupdates = true\n        symlinks = false\n        ignorecase = true\n        worktree = ../../../../target/upstream\n[remote \"origin\"]\n        url = C:/Users/bion/Desktop/upstream\n        fetch = +refs/heads/*:refs/remotes/origin/*\n[branch \"master\"]\n        remote = origin\n        merge = refs/heads/master\n\nNow try to go back to the previous commit using git reset --hard:\ngit log --oneline\n 1f560be (HEAD -> master) Moved submodule parent directory.\n a5977ce Add submodule in start/upstream.\ngit reset --hard a5977ce\n warning: unable to rmdir target/upstream: Directory not empty\n HEAD is now at a5977ce Add submodule in start/upstream.\n\nCheck that the worktree got fixed correctly; it did not:\ntype .git\\modules\\start\\upstream\\config\n[core]\n        repositoryformatversion = 0\n        filemode = false\n        bare = false\n        logallrefupdates = true\n        symlinks = false\n        ignorecase = true\n        worktree = ../../../../target/upstream\n[remote \"origin\"]\n        url = C:/Users/bion/Desktop/upstream\n        fetch = +refs/heads/*:refs/remotes/origin/*\n[branch \"master\"]\n        remote = origin\n        merge = refs/heads/master\n\nIs git reset intended to put the submodule in the right place? If not, is there a command we can run before/after reset to restore consistency?\n\nThanks folks!\n\nBilly O'Neal\n\n"},{"id":"331938","messageId":"CAGZ79kZRa6=PNtRoVMzM89ek+9uv9_+C+3-hNAaJ_W=YoeWj-w@mail.gmail.com","threadId":"47116","inReplyTo":"BN6PR21MB0114B8ECD6E8A158FB4A6FBFCB520@BN6PR21MB0114.namprd21.prod.outlook.com","subject":"Re: Bug report: git reset --hard does not fix submodule worktree","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-11-06T20:50:42Z","receivedAt":"2017-11-06T20:50:49Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Nov 3, 2017 at 5:46 PM, Billy O'Neal (VC LIBS)\n<bion@microsoft.com> wrote:\n> Hello, Git folks. I managed to accidentally break the our test lab by attempting to git mv a directory with a submodule inside. It seems like if a reset does an undo on a mv, the workfold entry should be fixed to put the submodule in its old location. Consider the following sequence of commands:\n>\n> Setup a git repo with a submodule:\n> mkdir metaproject\n> mkdir upstream\n> cd metaproject\n> git init\n> cd ..\\upstream\n> git init\n> echo hello > test.txt\n> git add -A\n> git commit -m \"an example commit\"\n> cd ..\\metapoject\n> mkdir start\n> git submodule add ../upstream start/upstream\n> git add -A\n> git commit -m \"Add submodule in start/upstream.\"\n>\n> Move the directory containing the submodule:\n> git mv start target\n> git add -A\n> git commit -m \"Moved submodule parent directory.\"\n>\n> Check that the worktree got correctly fixed by git mv; this output is as expected:\n> type .git\\modules\\start\\upstream\\config\n> [core]\n>         repositoryformatversion = 0\n>         filemode = false\n>         bare = false\n>         logallrefupdates = true\n>         symlinks = false\n>         ignorecase = true\n>         worktree = ../../../../target/upstream\n> [remote \"origin\"]\n>         url = C:/Users/bion/Desktop/upstream\n>         fetch = +refs/heads/*:refs/remotes/origin/*\n> [branch \"master\"]\n>         remote = origin\n>         merge = refs/heads/master\n>\n> Now try to go back to the previous commit using git reset --hard:\n> git log --oneline\n>  1f560be (HEAD -> master) Moved submodule parent directory.\n>  a5977ce Add submodule in start/upstream.\n> git reset --hard a5977ce\n>  warning: unable to rmdir target/upstream: Directory not empty\n>  HEAD is now at a5977ce Add submodule in start/upstream.\n>\n> Check that the worktree got fixed correctly; it did not:\n> type .git\\modules\\start\\upstream\\config\n> [core]\n>         repositoryformatversion = 0\n>         filemode = false\n>         bare = false\n>         logallrefupdates = true\n>         symlinks = false\n>         ignorecase = true\n>         worktree = ../../../../target/upstream\n> [remote \"origin\"]\n>         url = C:/Users/bion/Desktop/upstream\n>         fetch = +refs/heads/*:refs/remotes/origin/*\n> [branch \"master\"]\n>         remote = origin\n>         merge = refs/heads/master\n>\n> Is git reset intended to put the submodule in the right place?\n>\n> Thanks folks!\n\ngit-reset sounds like it ought to put submodules back into another directory.\nHistorically git-reset did not touch submodules at all; a recent\nrelease introduced\nthe --recurse-submodules flag for git-reset, which would cover this situation.\nHowever that particular situation (with moving the submodules) seems to be\nnot covered yet,\n\n./t7112-reset-submodule.sh\n...\nnot ok 69 - git reset --hard: replace submodule with a directory must\nfail # TODO known breakage\n\n\n\n> If not, is there a command we can run before/after reset to restore consistency?\n\nThe submodule \"fix-it-all\" command would be\n\n    git submodule update --init --recursive\n\nIMHO.\n"}]}