Skip to contentSkip to conversation

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

PATCH In review Kevin Ballard 2 participants 7 messages Jun 15, 2016 – Aug 13, 2016

lore
Share & tools
lore
#1 lore raw
In reply to Kevin Ballard
Quoted 4 lines · Kevin Ballard

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.

Quoted 29 lines
t/t7003-filter-branch.sh +13 -0
index 868babc..933157b 100755
@@ -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
Signature · 6 lines
1.5.4.3.487.g5a92

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Kevin Ballard

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.

Quoted 2 lines

* 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.

Quoted 1 line

I can fix-up and forge your Sign-off.

That would be great, thanks.

Quoted 31 lines
Quoted 30 lines
t/t7003-filter-branch.sh +0 -0
index 868babc..933157b 100755
@@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
 

'

+test_expect_success 'Subdirectory filter on folder with non- contiguous history' '

t/t7003-filter-branch.sh +12 -0
+	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

Signature · 6 lines
1.5.4.3.487.g5a92

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Kevin Ballard
http://kevin.sb.org
[email protected]
http://www.tildesoft.com
#3 lore raw

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.

---

* -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(-)
git-filter-branch.sh +10 -1
index 49e13f0..010353a 100755
@@ -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
t/t7003-filter-branch.sh +24 -0
index 868babc..6e14bf1 100755
@@ -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
#4 lore raw
Quoted 1 line · Junio C Hamano

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

Quoted 77 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.

---

* -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(-)
git-filter-branch.sh +10 -1
index 49e13f0..010353a 100755
@@ -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
t/t7003-filter-branch.sh +0 -0
index 868babc..6e14bf1 100755
@@ -179,4 +179,28 @@ test_expect_success 'Name needing quotes' '
 

'

t/t7003-filter-branch.sh +24 -0
+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

Signature · 4 lines
Kevin Ballard
http://kevin.sb.org
[email protected]
http://www.tildesoft.com
#5 lore raw

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

In reply to Kevin Ballard
Quoted 15 lines · Kevin Ballard
Quoted 5 lines · Junio C Hamano

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.

Quoted 3 lines

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

Quoted 8 lines

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.

Quoted 1 line

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(-)
git-filter-branch.sh +10 -1
index 49e13f0..8382212 100755
@@ -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
t/t7003-filter-branch.sh +4 -1
index 2ea8e3b..8f92fef 100755
@@ -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
#6 lore raw
In reply to Kevin Ballard

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

Quoted 38 lines · Kevin Ballard

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(-)
t/t7003-filter-branch.sh +0 -0
index 868babc..933157b 100755
@@ -179,4 +179,17 @@ test_expect_success 'Name needing quotes' '
 

'

+test_expect_success 'Subdirectory filter on folder with non- contiguous history' '

t/t7003-filter-branch.sh +12 -0
+	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

Signature · 6 lines
1.5.4.3.487.g5a92

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Kevin Ballard
http://kevin.sb.org
[email protected]
http://www.tildesoft.com
#0 lore raw

PATCH 1/1 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(-)
t/t7003-filter-branch.sh +13 -0
index 868babc..933157b 100755
@@ -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
Signature · 1 line
1.5.4.3.487.g5a92