{"thread":{"id":"28278","subject":"Cannot rewrite branch(es) with a dirty working directory","startedAt":"2011-09-01T15:52:02Z","lastAt":"2011-09-02T05:52:16Z","messageCount":5,"participants":["James Blackburn","Matthieu Moy","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"174670","messageId":"CACyv8dfL-G0Px0aFe3VFNHP-1xRUDLsFxgUu3amPGzO7qKp7jQ@mail.gmail.com","threadId":"28278","inReplyTo":null,"subject":"Cannot rewrite branch(es) with a dirty working directory","fromName":"James Blackburn","fromEmail":"jamesblackburn@gmail.com","sentAt":"2011-09-01T15:52:02Z","receivedAt":"2011-09-01T15:52:02Z","isPatch":false,"sender":{"key":"jamesblackburn@gmail.com","avatar":"https://gravatar.com/avatar/dacd1de956aceccae413b86cfb42fa952deb80631f85c4be6da4093e37416479?d=mp&s=160"},"body":"Hi All,\n\nI get a spurious:\n\"Cannot rewrite branch(es) with a dirty working directory.\"\ntrying to filter-branch in a clean git repo (having done a reset). The\nerror disappears when I do git status.\n\nLog of the shell commands:\nbash:jamesb:xl-cbga-20:33083> mkdir org.eclipse.cdt.core.linux.ia64\nbash:jamesb:xl-cbga-20:33084> cp -r\n../../../CDT_HEAD_GIT/org.eclipse.cdt/.git\norg.eclipse.cdt.core.linux.ia64/\nbash:jamesb:xl-cbga-20:33085> cd org.eclipse.cdt.core.linux.ia64/\nmbash:jamesb:xl-cbga-20:33086> git reset --hard\nChecking out files: 100% (11879/11879), done.\nHEAD is now at a03d454 Build against a local mirror of the 3.7 p2 repo\nbash:jamesb:xl-cbga-20:33087> git filter-branch --subdirectory-filter\ncore/org.eclipse.cdt.core.linux.ia64 -- master\nCannot rewrite branch(es) with a dirty working directory.\nbash:jamesb:xl-cbga-20:33088> git status\n# On branch master\nnothing to commit (working directory clean)\nbash:jamesb:xl-cbga-20:33089> git filter-branch --subdirectory-filter\ncore/org.eclipse.cdt.core.linux.ia64 -- master\nRewrite d7092b12c93925f6f7c4725a5abc72e55650621c (16/16)\nRef 'refs/heads/master' was rewritten\nbash:jamesb:xl-cbga-20:33090> git --version\ngit version 1.7.3.2\n\nIs there a particular reason why filter-branch thinks the tree is\ndirty, and status magically fixes this?\n\nCheers,\nJames\n"},{"id":"174689","messageId":"vpqmxeoqj61.fsf@bauges.imag.fr","threadId":"28278","inReplyTo":"CACyv8dfL-G0Px0aFe3VFNHP-1xRUDLsFxgUu3amPGzO7qKp7jQ@mail.gmail.com","subject":"Re: Cannot rewrite branch(es) with a dirty working directory","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-09-01T17:14:30Z","receivedAt":"2011-09-01T17:14:30Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"James Blackburn <jamesblackburn@gmail.com> writes:\n\n> Is there a particular reason why filter-branch thinks the tree is\n> dirty,\n\nNo idea. It comes after a \"git reset --hard\", so it's supposed to be\nclean.\n\n> and status magically fixes this?\n\nThe index is considered dirty if the stat information (timestamp) is\ndifferent. \"git status\" updates the stat-cache to consider unmodified\ncontent as up-to-date. So, it's normal that a \"git status\" repairs the\ndirty index.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"174710","messageId":"20110901215003.GC16308@sigill.intra.peff.net","threadId":"28278","inReplyTo":"vpqmxeoqj61.fsf@bauges.imag.fr","subject":"Re: Cannot rewrite branch(es) with a dirty working directory","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-09-01T21:50:03Z","receivedAt":"2011-09-01T21:50:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Sep 01, 2011 at 07:14:30PM +0200, Matthieu Moy wrote:\n\n> James Blackburn <jamesblackburn@gmail.com> writes:\n> \n> > Is there a particular reason why filter-branch thinks the tree is\n> > dirty,\n> \n> No idea. It comes after a \"git reset --hard\", so it's supposed to be\n> clean.\n\nI wonder if there are racily clean entries[1] in the index, and\ndiff-index reports them as potential changes.\n\nAt any rate, filter-branch should probably be refreshing the index\nbefore checking for dirtiness, which would give the correct answer\neither way.\n\n-Peff\n\n[1] See Documentation/technical/racy-git.txt for more information.\n"},{"id":"174711","messageId":"20110901215306.GD16308@sigill.intra.peff.net","threadId":"28278","inReplyTo":"20110901215003.GC16308@sigill.intra.peff.net","subject":"Re: Cannot rewrite branch(es) with a dirty working directory","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-09-01T21:53:07Z","receivedAt":"2011-09-01T21:53:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Sep 01, 2011 at 05:50:03PM -0400, Jeff King wrote:\n\n> > No idea. It comes after a \"git reset --hard\", so it's supposed to be\n> > clean.\n> \n> I wonder if there are racily clean entries[1] in the index, and\n> diff-index reports them as potential changes.\n> \n> At any rate, filter-branch should probably be refreshing the index\n> before checking for dirtiness, which would give the correct answer\n> either way.\n\nActually, we've already factored this logic out, so let's use it.\n\n-- >8 --\nSubject: filter-branch: use require_clean_work_tree\n\nFilter-branch already requires that we have a clean work\ntree before starting. However, it failed to refresh the\nindex before checking, which means it could be wrong in the\ncase of stat-dirtiness.\n\nInstead of simply adding a call to refresh the index, let's\nswitch to using the require_clean_work_tree function\nprovided by git-sh-setup. It does exactly what we want, and\nwith fewer lines of code and more specific output messages.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n git-filter-branch.sh |    4 +---\n 1 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 804a7f4..add2c02 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -108,9 +108,7 @@ OPTIONS_SPEC=\n . git-sh-setup\n \n if [ \"$(is_bare_repository)\" = false ]; then\n-\tgit diff-files --ignore-submodules --quiet &&\n-\tgit diff-index --cached --quiet HEAD -- ||\n-\tdie \"Cannot rewrite branch(es) with a dirty working directory.\"\n+\trequire_clean_work_tree 'rewrite branches'\n fi\n \n tempdir=.git-rewrite\n-- \n1.7.6.10.g62f04\n"},{"id":"174732","messageId":"vpqpqjjlcdr.fsf@bauges.imag.fr","threadId":"28278","inReplyTo":"20110901215306.GD16308@sigill.intra.peff.net","subject":"Re: Cannot rewrite branch(es) with a dirty working directory","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-09-02T05:52:16Z","receivedAt":"2011-09-02T05:52:16Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jeff King <peff@peff.net> writes:\n\n> --- a/git-filter-branch.sh\n> +++ b/git-filter-branch.sh\n> @@ -108,9 +108,7 @@ OPTIONS_SPEC=\n>  . git-sh-setup\n>  \n>  if [ \"$(is_bare_repository)\" = false ]; then\n> -\tgit diff-files --ignore-submodules --quiet &&\n> -\tgit diff-index --cached --quiet HEAD -- ||\n> -\tdie \"Cannot rewrite branch(es) with a dirty working directory.\"\n> +\trequire_clean_work_tree 'rewrite branches'\n>  fi\n>  \n>  tempdir=.git-rewrite\n\nSounds good, yes.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}