threads / patch / 12572

patchRe: [PATCH] Add test for filter-branch on a subdirectory that's been added and deleted and re-added

Subject: Re: [PATCH] Add test for filter-branch on a subdirectory that's been added and deleted and re-added

## tl;dr

7 messages between Mar 8, 2008 and Mar 8, 2008. Diffs are folded; open one to read it.

replies: 6people: 2as markdown or json

Kevin Ballard· Mar 8, 2008, 11:50 UTC · lore

[PATCH] Add test for filter-branch on a subdirectory that's been added and deleted and re-added

Add a currently-failing test for the case when git-filter-branch
is run with the --subdirectory-filter referencing a folder that
has been added, deleted, and re-added. Such an action should work,
but as this test shows it ends up blowing up.
---
 t/t7003-filter-branch.sh |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
Show changes to t/t7003-filter-branch.sh +13 −0
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 868babc..933157b 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
 
 '
 
+test_expect_success 'Subdirectory filter on folder with non-contiguous history' '
+	mkdir foo &&
+	touch foo/bar &&
+	git add foo &&
+	git commit -m "Adding foo" &&
+	git rm -r foo &&
+	git commit -m "Removing foo" &&
+	mkdir foo &&
+	touch foo/bar &&
+	git commit -m "Re-adding foo" &&
+	git filter-branch --subdirectory-filter foo
+'
+
 test_done
-- 
1.5.4.3.487.g5a92
Kevin Ballard· Mar 8, 2008, 11:52 UTC · re: Kevin Ballard · lore

Damnit, I just send those patches without the Signed-Off line. Should I re-send, or is it acceptable to just say I'm signing off on these and anyone is free to add my Signed-Off line when committing?

-Kevin Ballard
On Mar 8, 2008, at 6:50 AM, Kevin Ballard wrote:
Show 38 quoted lines
> Add a currently-failing test for the case when git-filter-branch
> is run with the --subdirectory-filter referencing a folder that
> has been added, deleted, and re-added. Such an action should work,
> but as this test shows it ends up blowing up.
> ---
> t/t7003-filter-branch.sh |   13 +++++++++++++
> 1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 868babc..933157b 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
>
> '
>
> +test_expect_success 'Subdirectory filter on folder with non- 
> contiguous history' '
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git add foo &&
> +	git commit -m "Adding foo" &&
> +	git rm -r foo &&
> +	git commit -m "Removing foo" &&
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git commit -m "Re-adding foo" &&
> +	git filter-branch --subdirectory-filter foo
> +'
> +
> test_done
> -- 
> 1.5.4.3.487.g5a92
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Kevin Ballard
http://kevin.sb.org
kevin@sb.org
http://www.tildesoft.com
Junio C Hamano· Mar 8, 2008, 18:41 UTC · re: Kevin Ballard · lore
Kevin Ballard <kevin@sb.org> writes:
> Add a currently-failing test for the case when git-filter-branch
> is run with the --subdirectory-filter referencing a folder that
> has been added, deleted, and re-added. Such an action should work,
> but as this test shows it ends up blowing up.

Such a test is a very good incentive to the people involved in the failing part of the system to fix, and is greatly appreciated. However,

 * please mark "currently-failing" test with "test_expect_failure";
 * please hint (after --- lines) if you will shortly be following up with
   a fix patch yourself, or if you are only reporting a bug.
I can fix-up and forge your Sign-off.
Show 29 quoted lines
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 868babc..933157b 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
>  
>  '
>  
> +test_expect_success 'Subdirectory filter on folder with non-contiguous history' '
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git add foo &&
> +	git commit -m "Adding foo" &&
> +	git rm -r foo &&
> +	git commit -m "Removing foo" &&
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git commit -m "Re-adding foo" &&
> +	git filter-branch --subdirectory-filter foo
> +'
> +
>  test_done
> -- 
> 1.5.4.3.487.g5a92
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kevin Ballard· Mar 8, 2008, 18:45 UTC · re: Junio C Hamano · lore
On Mar 8, 2008, at 1:41 PM, Junio C Hamano wrote:
Show 12 quoted lines
> Kevin Ballard <kevin@sb.org> writes:
>
>> Add a currently-failing test for the case when git-filter-branch
>> is run with the --subdirectory-filter referencing a folder that
>> has been added, deleted, and re-added. Such an action should work,
>> but as this test shows it ends up blowing up.
>
> Such a test is a very good incentive to the people involved in the  
> failing
> part of the system to fix, and is greatly appreciated.  However,
>
> * please mark "currently-failing" test with "test_expect_failure";

Ahh, didn't know about that. In retrospect I should have been able to guess, though.

> * please hint (after --- lines) if you will shortly be following up  
> with
>   a fix patch yourself, or if you are only reporting a bug.

Ah. Yeah, I'm only reporting a bug. I don't know anything about how this stuff works, and the bug doesn't bite me, it bit someone else instead, I just thought it deserved to be documented somewhere as a failure.

> I can fix-up and forge your Sign-off.
That would be great, thanks.
Show 31 quoted lines
>> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
>> index 868babc..933157b 100755
>> --- a/t/t7003-filter-branch.sh
>> +++ b/t/t7003-filter-branch.sh
>> @@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
>>
>> '
>>
>> +test_expect_success 'Subdirectory filter on folder with non- 
>> contiguous history' '
>> +	mkdir foo &&
>> +	touch foo/bar &&
>> +	git add foo &&
>> +	git commit -m "Adding foo" &&
>> +	git rm -r foo &&
>> +	git commit -m "Removing foo" &&
>> +	mkdir foo &&
>> +	touch foo/bar &&
>> +	git commit -m "Re-adding foo" &&
>> +	git filter-branch --subdirectory-filter foo
>> +'
>> +
>> test_done
>> -- 
>> 1.5.4.3.487.g5a92
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Kevin Ballard
http://kevin.sb.org
kevin@sb.org
http://www.tildesoft.com
Junio C Hamano· Mar 8, 2008, 20:08 UTC · re: Kevin Ballard · lore

Re* [PATCH] Add test for filter-branch on a subdirectory that's been added and deleted and re-added

Kevin Ballard <kevin@sb.org> writes:
Show 23 quoted lines
> On Mar 8, 2008, at 1:41 PM, Junio C Hamano wrote:
>
>> Such a test is a very good incentive to the people involved in the
>> failing
>> part of the system to fix, and is greatly appreciated.  However,
>>
>> * please mark "currently-failing" test with "test_expect_failure";
>
> Ahh, didn't know about that. In retrospect I should have been able to
> guess, though.
>
>> * please hint (after --- lines) if you will shortly be following up
>> with
>>   a fix patch yourself, or if you are only reporting a bug.
>
> Ah. Yeah, I'm only reporting a bug. I don't know anything about how
> this stuff works, and the bug doesn't bite me, it bit someone else
> instead, I just thought it deserved to be documented somewhere as a
> failure.
>
>> I can fix-up and forge your Sign-off.
>
> That would be great, thanks.
Heh, your test is broken.  You are not re-adding foo.
Here is a fix.
---
 git-filter-branch.sh     |   11 ++++++++++-
 t/t7003-filter-branch.sh |    5 ++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
Show changes to 2 files +14 −2

git-filter-branch.sh, t/t7003-filter-branch.sh

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 49e13f0..8382212 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -252,7 +252,16 @@ while read commit parents; do
 		git read-tree -i -m $commit
 		;;
 	*)
-		git read-tree -i -m $commit:"$filter_subdir"
+		# The commit may not have the subdirectory at all
+		err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
+		    if ! git rev-parse $commit:"$filter_subdir" 2>&1
+			then
+				rm -f "$GIT_INDEX_FILE"
+			else
+				echo >&2 "$err"
+				false
+			fi
+		}
 	esac || die "Could not initialize the index"
 
 	GIT_COMMIT=$commit
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 2ea8e3b..8f92fef 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -188,8 +188,11 @@ test_expect_failure 'Subdirectory filter on folder with non-contiguous history'
 	git commit -m "Removing foo" &&
 	mkdir foo &&
 	touch foo/bar &&
+	git add foo &&
 	git commit -m "Re-adding foo" &&
-	git filter-branch --subdirectory-filter foo
+
+	git filter-branch --subdirectory-filter foo &&
+	test $(git rev-list master | wc -l) = 3
 '
 
 test_done
Junio C Hamano· Mar 8, 2008, 20:25 UTC · re: Kevin Ballard · lore
This will hopefully be the final version.

-- >8 -- filter-branch: handle "disappearing tree" case correctly in subdir filter

The subdirectory filter had a bug to notice that the commit in question did not have anything in the path-limited part of the tree. $commit:$path does not name an empty tree when $path does not appear in $commit.

This should fix it. The additional test in t7003 is originally from Kevin Ballard but with fixups.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * -f is needed because the previous one is about aborting the filter and
    leaving the "original" namespace.
 git-filter-branch.sh     |   11 ++++++++++-
 t/t7003-filter-branch.sh |   24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)
Show changes to 2 files +34 −1

git-filter-branch.sh, t/t7003-filter-branch.sh

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 49e13f0..010353a 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -252,7 +252,16 @@ while read commit parents; do
 		git read-tree -i -m $commit
 		;;
 	*)
-		git read-tree -i -m $commit:"$filter_subdir"
+		# The commit may not have the subdirectory at all
+		err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
+			if ! git rev-parse --verify $commit:"$filter_subdir" 2>/dev/null
+			then
+				rm -f "$GIT_INDEX_FILE"
+			else
+				echo >&2 "$err"
+				false
+			fi
+		}
 	esac || die "Could not initialize the index"
 
 	GIT_COMMIT=$commit
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 868babc..6e14bf1 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -179,4 +179,28 @@ test_expect_success 'Name needing quotes' '
 
 '
 
+test_expect_success 'Subdirectory filter with disappearing trees' '
+	git reset --hard &&
+	git checkout master &&
+
+	mkdir foo &&
+	touch foo/bar &&
+	git add foo &&
+	test_tick &&
+	git commit -m "Adding foo" &&
+
+	git rm -r foo &&
+	test_tick &&
+	git commit -m "Removing foo" &&
+
+	mkdir foo &&
+	touch foo/bar &&
+	git add foo &&
+	test_tick &&
+	git commit -m "Re-adding foo" &&
+
+	git filter-branch -f --subdirectory-filter foo &&
+	test $(git rev-list master | wc -l) = 3
+'
+
 test_done
Kevin Ballard· Mar 8, 2008, 20:39 UTC · re: Junio C Hamano · lore
On Mar 8, 2008, at 3:25 PM, Junio C Hamano wrote:
> This will hopefully be the final version.

Assuming that the lack of a GIT_INDEX_FILE doesn't break git-checkout- index, git-diff-index, git-update-index, or anything that an --index- filter might run (I assume it doesn't, but I didn't test all the relevant commands), then this looks fine by me.

-Kevin
Show 82 quoted lines
>
> -- >8 --
> filter-branch: handle "disappearing tree" case correctly in subdir  
> filter
>
> The subdirectory filter had a bug to notice that the commit in  
> question
> did not have anything in the path-limited part of the tree.  $commit: 
> $path
> does not name an empty tree when $path does not appear in $commit.
>
> This should fix it.  The additional test in t7003 is originally from  
> Kevin
> Ballard but with fixups.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * -f is needed because the previous one is about aborting the filter  
> and
>    leaving the "original" namespace.
>
> git-filter-branch.sh     |   11 ++++++++++-
> t/t7003-filter-branch.sh |   24 ++++++++++++++++++++++++
> 2 files changed, 34 insertions(+), 1 deletions(-)
>
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 49e13f0..010353a 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -252,7 +252,16 @@ while read commit parents; do
> 		git read-tree -i -m $commit
> 		;;
> 	*)
> -		git read-tree -i -m $commit:"$filter_subdir"
> +		# The commit may not have the subdirectory at all
> +		err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
> +			if ! git rev-parse --verify $commit:"$filter_subdir" 2>/dev/null
> +			then
> +				rm -f "$GIT_INDEX_FILE"
> +			else
> +				echo >&2 "$err"
> +				false
> +			fi
> +		}
> 	esac || die "Could not initialize the index"
>
> 	GIT_COMMIT=$commit
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 868babc..6e14bf1 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -179,4 +179,28 @@ test_expect_success 'Name needing quotes' '
>
> '
>
> +test_expect_success 'Subdirectory filter with disappearing trees' '
> +	git reset --hard &&
> +	git checkout master &&
> +
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git add foo &&
> +	test_tick &&
> +	git commit -m "Adding foo" &&
> +
> +	git rm -r foo &&
> +	test_tick &&
> +	git commit -m "Removing foo" &&
> +
> +	mkdir foo &&
> +	touch foo/bar &&
> +	git add foo &&
> +	test_tick &&
> +	git commit -m "Re-adding foo" &&
> +
> +	git filter-branch -f --subdirectory-filter foo &&
> +	test $(git rev-list master | wc -l) = 3
> +'
> +
> test_done
>
-- 
Kevin Ballard
http://kevin.sb.org
kevin@sb.org
http://www.tildesoft.com

← back to recent threads