# [PATCH] filter-branch: do not consider diverging submodules a 'dirty worktree'

3 messages from 2009-02-05 to 2009-02-05. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/17590

## Johannes Schindelin, 2009-02-05 17:37

Subject: [PATCH] filter-branch: do not consider diverging submodules a 'dirty worktree'
Message-ID: <26931410834b5297493543e2a1cb75c3b6bf008a.1233855372u.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/26931410834b5297493543e2a1cb75c3b6bf008a.1233855372u.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1233855372u.git.johannes.schindelin@gmx.de>

```
At the end of filter-branch in a non-bare repository, the work tree is
updated with "read-tree -m -u HEAD", to carry the change forward in case
the current branch was rewritten.  In order to avoid losing any local
change during this step, filter-branch refuses to work when there are
local changes in the work tree.

This "read-tree -m -u HEAD" operation does not affect what commit is
checked out in a submodule (iow, it does not touch .git/HEAD in a
submodule checkout), and checking if there is any local change to the
submodule is not useful.

Staged submodules _are_ considered to be 'dirty', however,  as the
"read-tree -m -u HEAD" could result in loss of staged information
otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-filter-branch.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index b75d0ba..9ffa655 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -108,8 +108,8 @@ OPTIONS_SPEC=
 . git-sh-setup
 
 if [ "$(is_bare_repository)" = false ]; then
-	git diff-files --quiet &&
-	git diff-index --cached --quiet HEAD -- ||
+	git diff-files --ignore-submodules --quiet &&
+	git diff-index --ignore-submodules --cached --quiet HEAD -- ||
 	die "Cannot rewrite branch(es) with a dirty working directory."
 fi
 
-- 
1.6.1.1.598.g140d5

```

## Junio C Hamano, 2009-02-05 17:43

Subject: Re: [PATCH] filter-branch: do not consider diverging submodules a 'dirty worktree'
Message-ID: <7vskmseq4t.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vskmseq4t.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <26931410834b5297493543e2a1cb75c3b6bf008a.1233855372u.git.johannes.schindelin@gmx.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> At the end of filter-branch in a non-bare repository, the work tree is
> updated with "read-tree -m -u HEAD", to carry the change forward in case
> the current branch was rewritten.  In order to avoid losing any local
> change during this step, filter-branch refuses to work when there are
> local changes in the work tree.
>
> This "read-tree -m -u HEAD" operation does not affect what commit is
> checked out in a submodule (iow, it does not touch .git/HEAD in a
> submodule checkout), and checking if there is any local change to the
> submodule is not useful.
>
> Staged submodules _are_ considered to be 'dirty', however,  as the
> "read-tree -m -u HEAD" could result in loss of staged information
> otherwise.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Thanks.  I still have one question.

By the last paragraph, do you mean "diff-index --cached" should be run
without --ignore-submodules?  That does not seem to match the text of the
patch.

> ---
>  git-filter-branch.sh |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index b75d0ba..9ffa655 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -108,8 +108,8 @@ OPTIONS_SPEC=
>  . git-sh-setup
>  
>  if [ "$(is_bare_repository)" = false ]; then
> -	git diff-files --quiet &&
> -	git diff-index --cached --quiet HEAD -- ||
> +	git diff-files --ignore-submodules --quiet &&
> +	git diff-index --ignore-submodules --cached --quiet HEAD -- ||
>  	die "Cannot rewrite branch(es) with a dirty working directory."
>  fi
>  
> -- 
> 1.6.1.1.598.g140d5

```

## Johannes Schindelin, 2009-02-05 18:19

Subject: [PATCH v3] filter-branch: do not consider diverging submodules a 'dirty worktree'
Message-ID: <66fcb5966bce35110c880b417e160a6442256593.1233857872u.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/66fcb5966bce35110c880b417e160a6442256593.1233857872u.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1233857872u.git.johannes.schindelin@gmx.de>

```
At the end of filter-branch in a non-bare repository, the work tree is
updated with "read-tree -m -u HEAD", to carry the change forward in case
the current branch was rewritten.  In order to avoid losing any local
change during this step, filter-branch refuses to work when there are
local changes in the work tree.

This "read-tree -m -u HEAD" operation does not affect what commit is
checked out in a submodule (iow, it does not touch .git/HEAD in a
submodule checkout), and checking if there is any local change to the
submodule is not useful.

Staged submodules _are_ considered to be 'dirty', however,  as the
"read-tree -m -u HEAD" could result in loss of staged information
otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	Of course I forgot the file name when I --amended the commit 
	message, so I forgot that change...

 git-filter-branch.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index b75d0ba..86eef56 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -108,7 +108,7 @@ OPTIONS_SPEC=
 . git-sh-setup
 
 if [ "$(is_bare_repository)" = false ]; then
-	git diff-files --quiet &&
+	git diff-files --ignore-submodules --quiet &&
 	git diff-index --cached --quiet HEAD -- ||
 	die "Cannot rewrite branch(es) with a dirty working directory."
 fi
-- 
1.6.1.1.598.g140d5

```
