summaryrefslogtreecommitdiff
path: root/t/t5700-clone-reference.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-08-10 09:34:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-10 22:15:42 (GMT)
commit77b9b1d13ac9e6b78ba676d4edb221b7d2273c62 (patch)
tree48dbdac8534c48be32d3e05dcb3846887d83fd6b /t/t5700-clone-reference.sh
parentbc192300c49a32e1ef297dc3fa78a101f28e2a4c (diff)
downloadgit-77b9b1d13ac9e6b78ba676d4edb221b7d2273c62.zip
git-77b9b1d13ac9e6b78ba676d4edb221b7d2273c62.tar.gz
git-77b9b1d13ac9e6b78ba676d4edb221b7d2273c62.tar.bz2
add_to_alternates_file: don't add duplicate entries
The add_to_alternates_file function blindly uses hold_lock_file_for_append to copy the existing contents, and then adds the new line to it. This has two minor problems: 1. We might add duplicate entries, which are ugly and inefficient. 2. We do not check that the file ends with a newline, in which case we would bogusly append to the final line. This is quite unlikely in practice, though, as we call this function only from git-clone, so presumably we are the only writers of the file (and we always add a newline). Instead of using hold_lock_file_for_append, let's copy the file line by line, which ensures all records are properly terminated. If we see an extra line, we can simply abort the update (there is no point in even copying the rest, as we know that it would be identical to the original). As a bonus, we also get rid of some calls to the static-buffer mkpath and git_path functions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5700-clone-reference.sh')
-rwxr-xr-xt/t5700-clone-reference.sh5
1 files changed, 5 insertions, 0 deletions
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 51d131a..ef1779f 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -120,6 +120,11 @@ test_expect_success 'cloning with reference being subset of source (-l -s)' '
git clone -l -s --reference A B E
'
+test_expect_success 'cloning with multiple references drops duplicates' '
+ git clone -s --reference B --reference A --reference B A dups &&
+ test_line_count = 2 dups/.git/objects/info/alternates
+'
+
test_expect_success 'clone with reference from a tagged repository' '
(
cd A && git tag -a -m tagged HEAD