From a3e826722515ec8abed8ccf29d958eb52d4be3f8 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 23 Jan 2009 10:07:18 +0100 Subject: replace_object: add a test case In this patch the setup code is very big, but this will be used in test cases that will be added later. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 t/t6050-replace.sh (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh new file mode 100755 index 0000000000..0a585ecda7 --- /dev/null +++ b/t/t6050-replace.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# +# Copyright (c) 2008 Christian Couder +# +test_description='Tests replace refs functionality' + +exec > hello && + echo "line 2" >> hello && + echo "line 3" >> hello && + echo "line 4" >> hello && + add_and_commit_file hello "4 lines" && + HASH1=$(git rev-parse --verify HEAD) && + echo "line BUG" >> hello && + echo "line 6" >> hello && + echo "line 7" >> hello && + echo "line 8" >> hello && + add_and_commit_file hello "4 more lines with a BUG" && + HASH2=$(git rev-parse --verify HEAD) && + echo "line 9" >> hello && + echo "line 10" >> hello && + add_and_commit_file hello "2 more lines" && + HASH3=$(git rev-parse --verify HEAD) && + echo "line 11" >> hello && + add_and_commit_file hello "1 more line" && + HASH4=$(git rev-parse --verify HEAD) && + sed -e "s/BUG/5/" hello > hello.new && + mv hello.new hello && + add_and_commit_file hello "BUG fixed" && + HASH5=$(git rev-parse --verify HEAD) && + echo "line 12" >> hello && + echo "line 13" >> hello && + add_and_commit_file hello "2 more lines" && + HASH6=$(git rev-parse --verify HEAD) + echo "line 14" >> hello && + echo "line 15" >> hello && + echo "line 16" >> hello && + add_and_commit_file hello "again 3 more lines" && + HASH7=$(git rev-parse --verify HEAD) +' + +test_expect_success 'replace the author' ' + git cat-file commit $HASH2 | grep "author A U Thor" && + R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) && + git cat-file commit $R | grep "author O Thor" && + git update-ref refs/replace/$HASH2 $R && + git show HEAD~5 | grep "O Thor" && + git show $HASH2 | grep "O Thor" +' + +# +# +test_done -- cgit v1.2.3 From cc400f50112a58471b992a54b1a05d99a8a82457 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 23 Jan 2009 10:07:26 +0100 Subject: mktag: call "check_sha1_signature" with the replacement sha1 Otherwise we get a "sha1 mismatch" error for replaced objects. Note that I am not sure at all that this is a good change. It may be that we should just refuse to tag a replaced object. But in this case we should probably give a meaningfull error message instead of "sha1 mismatch". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 0a585ecda7..334aed6216 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -70,6 +70,18 @@ test_expect_success 'replace the author' ' git show $HASH2 | grep "O Thor" ' +cat >tag.sig < 0 +0000 + +EOF + +test_expect_success 'tag replaced commit' ' + git mktag .git/refs/tags/mytag 2>message +' + # # test_done -- cgit v1.2.3 From dae556bdb1e2ad6fb5eafe82e975bde01029fca9 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 23 Jan 2009 10:07:46 +0100 Subject: environment: add global variable to disable replacement This new "read_replace_refs" global variable is set to 1 by default, so that replace refs are used by default. But reachability traversal and packing commands ("cmd_fsck", "cmd_prune", "cmd_pack_objects", "upload_pack", "cmd_unpack_objects") set it to 0, as they must work with the original DAG. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 334aed6216..17f6063207 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -82,6 +82,29 @@ test_expect_success 'tag replaced commit' ' git mktag .git/refs/tags/mytag 2>message ' +test_expect_success '"git fsck" works' ' + git fsck master > fsck_master.out && + grep "dangling commit $R" fsck_master.out && + grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + test -z "$(git fsck)" +' + +test_expect_success 'repack, clone and fetch work' ' + git repack -a -d && + git clone --no-hardlinks . clone_dir && + cd clone_dir && + git show HEAD~5 | grep "A U Thor" && + git show $HASH2 | grep "A U Thor" && + git cat-file commit $R && + git repack -a -d && + test_must_fail git cat-file commit $R && + git fetch ../ "refs/replace/*:refs/replace/*" && + git show HEAD~5 | grep "O Thor" && + git show $HASH2 | grep "O Thor" && + git cat-file commit $R && + cd .. +' + # # test_done -- cgit v1.2.3 From 54b0c1e041e50cc08b1520b7d557770916d0b7ab Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 2 Feb 2009 06:12:44 +0100 Subject: Add new "git replace" command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command can only be used now to list replace refs in "refs/replace/" and to delete them. The option to list replace refs is "-l". The option to delete replace refs is "-d". The behavior should be consistent with how "git tag" and "git branch" are working. The code has been copied from "builtin-tag.c" by Kristian Høgsberg and Carlos Rica that was itself based on git-tag.sh and mktag.c by Linus Torvalds. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 17f6063207..bf4c93f7f8 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -105,6 +105,18 @@ test_expect_success 'repack, clone and fetch work' ' cd .. ' +test_expect_success '"git replace" listing and deleting' ' + test "$HASH2" = "$(git replace -l)" && + test "$HASH2" = "$(git replace)" && + aa=${HASH2%??????????????????????????????????????} && + test "$HASH2" = "$(git replace -l "$aa*")" && + test_must_fail git replace -d $R && + test_must_fail git replace -d && + test_must_fail git replace -l -d $HASH2 && + git replace -d $HASH2 && + test -z "$(git replace -l)" +' + # # test_done -- cgit v1.2.3 From bebdd271ff660d603ad75fef346ad1ff19fca0cb Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 2 Feb 2009 06:12:53 +0100 Subject: builtin-replace: teach "git replace" to actually replace Teach the syntax: "git replace ", so that "git replace" can now create replace refs. These replace refs will be used by read_sha1_file to substitute with for most of the commands. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index bf4c93f7f8..448a19a5ec 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -114,9 +114,19 @@ test_expect_success '"git replace" listing and deleting' ' test_must_fail git replace -d && test_must_fail git replace -l -d $HASH2 && git replace -d $HASH2 && + git show $HASH2 | grep "A U Thor" && test -z "$(git replace -l)" ' +test_expect_success '"git replace" replacing' ' + git replace $HASH2 $R && + git show $HASH2 | grep "O Thor" && + test_must_fail git replace $HASH2 $R && + git replace -f $HASH2 $R && + test_must_fail git replace -f && + test "$HASH2" = "$(git replace)" +' + # # test_done -- cgit v1.2.3 From 4e65b538acc97dd853e19a1692893f5fd47043e6 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Wed, 27 May 2009 07:14:09 +0200 Subject: t6050: check pushing something based on a replaced commit When using something like: $ git push $there 04a8c^2:master we need to parse 04a8c to find its second parent and then start discussing what object to send with the other end. "04a8c^2" is a direct user input and should mean the same commit as git show "04a8c^2" would give the user, so it obviously needs to obey the replace rules (making 04a8c parsed), but the object transfer should not look at replace at all. This patch adds some tests to check that the above is working well. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 't') diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 448a19a5ec..8b8bd81c09 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -127,6 +127,74 @@ test_expect_success '"git replace" replacing' ' test "$HASH2" = "$(git replace)" ' +# This creates a side branch where the bug in H2 +# does not appear because P2 is created by applying +# H2 and squashing H5 into it. +# P3, P4 and P6 are created by cherry-picking H3, H4 +# and H6 respectively. +# +# At this point, we should have the following: +# +# P2--P3--P4--P6 +# / +# H1-H2-H3-H4-H5-H6-H7 +# +# Then we replace H6 with P6. +# +test_expect_success 'create parallel branch without the bug' ' + git replace -d $HASH2 && + git show $HASH2 | grep "A U Thor" && + git checkout $HASH1 && + git cherry-pick $HASH2 && + git show $HASH5 | git apply && + git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello && + PARA2=$(git rev-parse --verify HEAD) && + git cherry-pick $HASH3 && + PARA3=$(git rev-parse --verify HEAD) && + git cherry-pick $HASH4 && + PARA4=$(git rev-parse --verify HEAD) && + git cherry-pick $HASH6 && + PARA6=$(git rev-parse --verify HEAD) && + git replace $HASH6 $PARA6 && + git checkout master && + cur=$(git rev-parse --verify HEAD) && + test "$cur" = "$HASH7" && + git log --pretty=oneline | grep $PARA2 && + git remote add cloned ./clone_dir +' + +test_expect_success 'push to cloned repo' ' + git push cloned $HASH6^:refs/heads/parallel && + cd clone_dir && + git checkout parallel && + git log --pretty=oneline | grep $PARA2 && + cd .. +' + +test_expect_success 'push branch with replacement' ' + git cat-file commit $PARA3 | grep "author A U Thor" && + S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) && + git cat-file commit $S | grep "author O Thor" && + git replace $PARA3 $S && + git show $HASH6~2 | grep "O Thor" && + git show $PARA3 | grep "O Thor" && + git push cloned $HASH6^:refs/heads/parallel2 && + cd clone_dir && + git checkout parallel2 && + git log --pretty=oneline | grep $PARA3 && + git show $PARA3 | grep "A U Thor" && + cd .. +' + +test_expect_success 'fetch branch with replacement' ' + git branch tofetch $HASH6 && + cd clone_dir && + git fetch origin refs/heads/tofetch:refs/heads/parallel3 + git log --pretty=oneline parallel3 | grep $PARA3 + git show $PARA3 | grep "A U Thor" + cd .. +' + # # test_done -- cgit v1.2.3