[PATCH 01/22] t3204: test deleting references when lock files already exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When deleting a reference, it might be that another process already
holds the lock on the loose reference file and/or the packed-refs
file.  In those cases, there is no alternative but for the delete to
fail.  Verify that in such cases the reference values are left
unchanged.

But in fact, when the packed-refs file lock cannot be acquired, the
loose reference file is deleted anyway, potentially leaving the
reference with a changed value (its packed value, which might even
point at an object that has been garbage collected).  Thus one of the
new tests is marked test_expect_failure.

Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx>
---
 t/t3204-branch-locks.sh | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 t/t3204-branch-locks.sh

diff --git a/t/t3204-branch-locks.sh b/t/t3204-branch-locks.sh
new file mode 100755
index 0000000..cc4e2c1
--- /dev/null
+++ b/t/t3204-branch-locks.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+test_description='git branch lock tests'
+
+. ./test-lib.sh
+
+test_expect_success 'prepare a trivial repository' '
+	git commit --allow-empty -m "Initial" &&
+	git commit --allow-empty -m "First"
+'
+
+test_expect_success 'delete a ref while loose ref file is locked' '
+	git branch b1 master &&
+	git for-each-ref >expected1 &&
+	# Simulate another process holding the loose file lock:
+	: >.git/refs/heads/b1.lock &&
+	test_must_fail git branch -D b1 &&
+	rm .git/refs/heads/b1.lock &&
+	# Delete failed; reference values should be unchanged:
+	git for-each-ref >actual1 &&
+	test_cmp expected1 actual1
+'
+
+test_expect_failure 'delete a ref while packed-refs file is locked' '
+	git branch b2 master &&
+	# Pack current value of b2:
+	git pack-refs --all &&
+	# Overwrite packed value with a loose value:
+	git branch -f b2 master^ &&
+	git for-each-ref >expected2 &&
+	# Simulate another process holding the packed-refs file lock:
+	: >.git/packed-refs.lock &&
+	test_must_fail git branch -D b2 &&
+	rm .git/packed-refs.lock &&
+	# Delete failed; reference values should be unchanged:
+	git for-each-ref >actual2 &&
+	test_cmp expected2 actual2
+'
+
+test_done
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]