git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Cannot rewrite branch(es) with a dirty working directory

From
Jeff King <peff@peff.net>
Date
Sep 1, 2011, 21:53 UTC
Message-ID
<20110901215306.GD16308@sigill.intra.peff.net>
In-Reply-To
<20110901215003.GC16308@sigill.intra.peff.net>
On Thu, Sep 01, 2011 at 05:50:03PM -0400, Jeff King wrote:
Show 9 quoted lines
> > No idea. It comes after a "git reset --hard", so it's supposed to be
> > clean.
> 
> I wonder if there are racily clean entries[1] in the index, and
> diff-index reports them as potential changes.
> 
> At any rate, filter-branch should probably be refreshing the index
> before checking for dirtiness, which would give the correct answer
> either way.
Actually, we've already factored this logic out, so let's use it.
-- >8 --
Subject: filter-branch: use require_clean_work_tree

Filter-branch already requires that we have a clean work tree before starting. However, it failed to refresh the index before checking, which means it could be wrong in the case of stat-dirtiness.

Instead of simply adding a call to refresh the index, let's switch to using the require_clean_work_tree function provided by git-sh-setup. It does exactly what we want, and with fewer lines of code and more specific output messages.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-filter-branch.sh |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 804a7f4..add2c02 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -108,9 +108,7 @@ OPTIONS_SPEC=
 . git-sh-setup
 
 if [ "$(is_bare_repository)" = false ]; then
-	git diff-files --ignore-submodules --quiet &&
-	git diff-index --cached --quiet HEAD -- ||
-	die "Cannot rewrite branch(es) with a dirty working directory."
+	require_clean_work_tree 'rewrite branches'
 fi
 
 tempdir=.git-rewrite
-- 
1.7.6.10.g62f04
Previous: Jeff KingNext: Matthieu Moy
Message 4 of 5 in “Cannot rewrite branch(es) with a dirty working directory”
  1. James BlackburnSep 1, 2011
  2. Matthieu MoySep 1, 2011
  3. Jeff KingSep 1, 2011
  4. Jeff KingSep 1, 2011
  5. Matthieu MoySep 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.