git alternate command
Here is the latest version of my git alternate command. The major difference to the last update is additional tests for deleting alternates and some updates to the test based on Hannes' feedback.
I still am intending to add documentation and to look into Stephens suggestions for changing the UI to use add|delete|show instead of -a|-d.
I'm also interested in any feedback regarding the actual output from the command.
Cheers,
Chris
---
Makefile | 1 + git-alternate.sh | 156 ++++++++++++++++++++++++++++++++++++++++++++++ t/t1430-alternate-cmd.sh | 154 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 311 insertions(+), 0 deletions(-)
PATCH v3 1/2 Add git alternate command
The current UI around alternates is lacking. There are commands to add an alternate at the time of a clone (e.g. 'git clone --reference') but no commands to see what alternates have been configured or to add an alternate after a repository has been cloned. This patch adds a friendlier UI for displaying and configuring alternates.
--- Makefile | 1 + git-alternate.sh | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 0 deletions(-) create mode 100755 git-alternate.sh
Makefile +1 -0
@@ -334,6 +334,7 @@ TEST_PROGRAMS_NEED_X = unexport CDPATH SCRIPT_SH += git-am.sh +SCRIPT_SH += git-alternate.sh SCRIPT_SH += git-bisect.sh SCRIPT_SH += git-difftool--helper.sh SCRIPT_SH += git-filter-branch.sh
git-alternate.sh new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
1.7.0.3
PATCH v3 2/2 tests for git alternate command
In reply to Chris Packham--- t/t1430-alternate-cmd.sh | 154 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 154 insertions(+), 0 deletions(-) create mode 100644 t/t1430-alternate-cmd.sh
t/t1430-alternate-cmd.sh new file +154 -0
@@ -0,0 +1,154 @@ +#!/bin/sh +# +# Copyright (c) Chris Packham +# + +test_description='Test of git alternate command' + +. ./test-lib.sh + +test_expect_success 'setup for rest of the test' ' + + mkdir -p base && + ( + cd base && + git init && + echo test > a.txt && + echo test > b.txt && + echo test > c.txt && + git add *.txt && + git commit -a -m "Initial Commit" + ) + git clone base A && + git clone A B && + git clone A C && + git clone A D + testbase=$(pwd) +' + +test_expect_success 'can add alternate after clone' ' + + ( + cd B && + git alternate -a ../base/.git/objects && + + echo "$testbase/base/.git/objects" > expect && + cp .git/objects/info/alternates actual && + + test_cmp expect actual + + ) +' + +test_expect_success 'add same alternate fails (absolute path)' ' + + ( + cd B && + test_must_fail git alternate -a $(pwd)/base/.git/objects + ) +' + +test_expect_success 'add same alternate fails (relative path)' ' + + ( + cd B && + test_must_fail git alternate -a ../base/.git/objects + ) +' + +test_expect_success 'can add multiple alternates' ' + + ( + cd C && + git alternate -a ../base/.git/objects && + git alternate -a ../B/.git/objects && + + { + echo "$testbase/base/.git/objects" + echo "$testbase/B/.git/objects" + } > expect && + + cp .git/objects/info/alternates actual && + + test_cmp expect actual + ) +' + +test_expect_success 'can add recursive alternate' ' + + ( + cd D && + git alternate -a ../C/.git/objects + + echo "$testbase/C/.git/objects" > expect && + cp .git/objects/info/alternates actual && + + test_cmp expect actual + ) +' + +test_expect_success 'simple display' ' + + ( + cd B && + git alternate >actual && + { + echo "Object store $testbase/base/.git/objects" + echo " referenced via $testbase/B/.git" + } >expect && + + test_cmp expect actual + ) +' + +test_expect_success 'recursive display' ' + + ( + cd D && + git alternate -r >actual && + + { + echo "Object store $testbase/C/.git/objects" + echo " referenced via $testbase/D/.git" + echo "Object store $testbase/base/.git/objects" + echo " referenced via $testbase/C/.git" + echo "Object store $testbase/B/.git/objects" + echo " referenced via $testbase/C/.git" + echo "Object store $testbase/base/.git/objects" + echo " referenced via $testbase/B/.git" + } >expect && + + test_cmp expect actual + ) +' + +test_expect_success 'cannot delete unless --forced' ' + ( + cd C && + test_must_fail git alternate -d "$testbase/B/.git/objects" + ) +' + +test_expect_success 'can delete one alternate' ' + ( + cd C && + git alternate -f -d "$testbase/B/.git/objects" && + + echo "$testbase/base/.git/objects" > expect && + cp .git/objects/info/alternates actual && + + test_cmp expect actual + ) +' + +test_expect_success 'last alternate deleted removes file' ' + ( + cd C && + git alternate -f -d "$testbase/base/.git/objects" && + + test ! -e .git/objects/info/alternates + + ) +' + +test_done
Signature · 1 line
1.7.0.3