Skip to contentSkip to conversation

t1402: check to delete broken refs

PATCH In review Stefan Beller 5 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t1402: check to delete broken refs

From: Ronnie Sahlberg <[email protected]>

---

This was also part of the ongoing series from Ronnie. But I think the patch in this form is rather independant, documenting the current state of "git branch -d", so it's fine to have it in now.

 t/t1402-check-ref-format.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
t/t1402-check-ref-format.sh +8 -0
index e5dc62e..08af156 100755
@@ -197,4 +197,12 @@ invalid_ref_normalized 'heads///foo.lock'
 invalid_ref_normalized 'foo.lock/bar'
 invalid_ref_normalized 'foo.lock///bar'
 
+test_expect_failure 'git branch -d can delete ref with broken sha1' '
+	echo "pointing nowhere" > .git/refs/heads/brokensha1 &&
+	test_when_finished "rm -f .git/refs/heads/brokensha1" &&
+	git branch -d brokensha1 &&
+	git branch >output &&
+	! grep -e "brokensha1" output
+'
+
 test_done
Signature · 1 line
2.2.0.rc3
#1 lore raw

Hi,

Quoted 4 lines · Stefan Beller

This was also part of the ongoing series from Ronnie. But I think the patch in this form is rather independant, documenting the current state of "git branch -d", so it's fine to have it in now.

Is there a patch adding the feature this patch describes that this could be squashed into?

Quoted 2 lines
 t/t1402-check-ref-format.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

This doesn't have anything to do with check-ref-format --- it's about how easy it is to recover from a repository with corrupt files in it. Would it fit somewhere like t3200-branch.sh?

#2 lore raw
Quoted 11 lines · Jonathan Nieder

Hi,

Quoted 4 lines · Stefan Beller

This was also part of the ongoing series from Ronnie. But I think the patch in this form is rather independant, documenting the current state of "git branch -d", so it's fine to have it in now.

Is there a patch adding the feature this patch describes that this could be squashed into?

I have extracted it actually from a patch, which it was part of. I want to send as much uncontroversial stuff to the list, before I try another round of the larger reflog transactions series.

For now this test just documents, how git branch is behaving differently from its desired behavior. So it is also a subtle proposal how the desired behavior should look like. (Deleting broken branches without further questioning, flags or other magic incantations)

Quoted 7 lines
Quoted 3 lines
 t/t1402-check-ref-format.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

This doesn't have anything to do with check-ref-format --- it's about how easy it is to recover from a repository with corrupt files in it. Would it fit somewhere like t3200-branch.sh?

I'll look into placing this test in a more appropriate spot.

#3 lore raw

PATCH v2 1/1 branch -d: test if we can delete broken refs

From: Ronnie Sahlberg <[email protected]>

---
Changes v1->v2
* relocated the test from t1402 to t3200
* reword the commit message title to fit in with similar commits touching t/t3200-branch.sh

 t/t3200-branch.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
t/t3200-branch.sh +8 -0
index 432921b..fa7d7bd 100755
@@ -163,6 +163,14 @@ test_expect_success 'git branch --list -d t should fail' '
 	test_path_is_missing .git/refs/heads/t
 '
 
+test_expect_failure 'git branch -d can delete ref with broken sha1' '
+	echo "pointing nowhere" > .git/refs/heads/brokensha1 &&
+	test_when_finished "rm -f .git/refs/heads/brokensha1" &&
+	git branch -d brokensha1 &&
+	git branch >output &&
+	! grep -e "brokensha1" output
+'
+
 test_expect_success 'git branch --column' '
 	COLUMNS=81 git branch --column=column >actual &&
 	cat >expected <<\EOF &&
Signature · 1 line
2.2.0.rc3
#4 lore raw

Re: [PATCHv2] branch -d: test if we can delete broken refs

Aside from one tiny formatting nit (see below), the test looks good to me. On the other hand, this is kind of an "aspirational test"; I don't know that the tested functionality has ever worked or that anybody has ever claimed that it works. So my feeling is that the addition of the test would feel more natural in the patch series that implements the new feature. But I don't feel strongly about it.

Michael

Quoted 18 lines · Stefan Beller

From: Ronnie Sahlberg <[email protected]>

---
Changes v1->v2
* relocated the test from t1402 to t3200
* reword the commit message title to fit in with similar commits touching t/t3200-branch.sh

 t/t3200-branch.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
t/t3200-branch.sh +0 -0
index 432921b..fa7d7bd 100755

t/t3200-branch.sh test_expect_success 'git branch --list -d t should fail' ' · line 167

Quoted 5 lines
t/t3200-branch.sh +2 -0
@@ -163,6 +163,14 @@ test_expect_success 'git branch --list -d t should fail' '
 	test_path_is_missing .git/refs/heads/t
 '
 
+test_expect_failure 'git branch -d can delete ref with broken sha1' '
+	echo "pointing nowhere" > .git/refs/heads/brokensha1 &&

Please no space between the ">" and the filename.

Quoted 10 lines
t/t3200-branch.sh +6 -0
+	test_when_finished "rm -f .git/refs/heads/brokensha1" &&
+	git branch -d brokensha1 &&
+	git branch >output &&
+	! grep -e "brokensha1" output
+'
+
 test_expect_success 'git branch --column' '
 	COLUMNS=81 git branch --column=column >actual &&
 	cat >expected <<\EOF &&
Signature · 3 lines
Michael Haggerty
[email protected]
http://softwareswirl.blogspot.com/
#5 lore raw

Re: [PATCHv2] branch -d: test if we can delete broken refs

Quoted 5 lines · Michael Haggerty

... On the other hand, this is kind of an "aspirational test"; I don't know that the tested functionality has ever worked or that anybody has ever claimed that it works. So my feeling is that the addition of the test would feel more natural in the patch series that implements the new feature. But I don't feel strongly about it.

I share your feeling.

In the "aspiration followed by realization" pattern, the realization commit shows a change in t/ hierarchy that turns test_expect_failure into test_expect_success and it is likely that what is being tested will fall outside the context. Unless the test title is phrased very well, it would not be obvious from the patch text to the t/ hierarchy alone what behaviour is being corrected when looking at the realization commit.

If aspiration and realization are in a same series, that would not be a problem, but it is if the commits that add "aspirational test" and "realization" are too far apart.

If it is pretty clear to everybody that another topic to realize the aspiration will be coming in a not so distant future, I think it is fine, though.

#6 lore raw
In reply to Stefan Beller
Quoted 19 lines · Stefan Beller

From: Ronnie Sahlberg <[email protected]>

---

This was also part of the ongoing series from Ronnie. But I think the patch in this form is rather independant, documenting the current state of "git branch -d", so it's fine to have it in now.

  t/t1402-check-ref-format.sh | 8 ++++++++
  1 file changed, 8 insertions(+)
t/t1402-check-ref-format.sh +0 -0
index e5dc62e..08af156 100755

t/t1402-check-ref-format.sh invalid_ref_normalized 'heads///foo.lock' · line 206

Quoted 10 lines
t/t1402-check-ref-format.sh +7 -0
@@ -197,4 +197,12 @@ invalid_ref_normalized 'heads///foo.lock'
  invalid_ref_normalized 'foo.lock/bar'
  invalid_ref_normalized 'foo.lock///bar'
 
+test_expect_failure 'git branch -d can delete ref with broken sha1' '
+	echo "pointing nowhere" > .git/refs/heads/brokensha1 &&
+	test_when_finished "rm -f .git/refs/heads/brokensha1" &&
+	git branch -d brokensha1 &&
+	git branch >output &&
+	! grep -e "brokensha1" output
+'

Do we need grep -e here ?
It does not give us anything in the pattern we are using.

-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This can be used to
specify multiple search patterns, or to protect a pattern beginning
with a hyphen (-). (-e is specified by POSIX.)

(And we do not need the "" either, there is no space in brokensha1) We can simply use:
! grep brokensha1 output

Quoted 2 lines
t/t1402-check-ref-format.sh +1 -0
+
  test_done
#7 lore raw

PATCH v3 1/1 branch -d: test if we can delete broken refs

From: Ronnie Sahlberg <[email protected]>

---
Changes v1->v2
* relocated the test from t1402 to t3200
* reword the commit message title to fit in with similar commits touching t/t3200-branch.sh

Changes v2 -> v3
* remove space nit pointed out by Michael
* simplified grep expression as pointed out by Torsten

I don't mind applying this one later as part of the series, where we actually introduce the feature. Thanks for all the feedback!

Michael writes

Quoted 5 lines

On the other hand, this is kind of an "aspirational test"; I don't know that the tested functionality has ever worked or that anybody has ever claimed that it works. So my feeling is that the addition of the test would feel more natural in the patch series that implements the new feature. But I don't feel strongly about it.

I don't have a strong oppinion on this one either. It's just my impression, that small single patches are digested easier by the mailing list rather than large series. So as the feedback is in, I'll put this patch at the end of the series, where the actual feature will be introduced.

 t/t3200-branch.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
t/t3200-branch.sh +8 -0
index 432921b..fa7d7bd 100755
@@ -163,6 +163,14 @@ test_expect_success 'git branch --list -d t should fail' '
 	test_path_is_missing .git/refs/heads/t
 '
 
+test_expect_failure 'git branch -d can delete ref with broken sha1' '
+	echo "pointing nowhere" >.git/refs/heads/brokensha1 &&
+	test_when_finished "rm -f .git/refs/heads/brokensha1" &&
+	git branch -d brokensha1 &&
+	git branch >output &&
+	! grep brokensha1 output
+'
+
 test_expect_success 'git branch --column' '
 	COLUMNS=81 git branch --column=column >actual &&
 	cat >expected <<\EOF &&
Signature · 1 line
2.2.0.rc3