about summary refs log tree commit diff
path: root/third_party/git/t/t0002-gitfile.sh
diff options
context:
space:
mode:
authorVincent Ambo <Vincent Ambo>2020-01-11T23·36+0000
committerVincent Ambo <Vincent Ambo>2020-01-11T23·40+0000
commit7ef0d62730840ded097b524104cc0a0904591a63 (patch)
treea670f96103667aeca4789a95d94ca0dff550c4ce /third_party/git/t/t0002-gitfile.sh
parent6a2a3007077818e24a3d56fc492ada9206a10cf0 (diff)
parent1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5 (diff)
merge(third_party/git): Merge squashed git subtree at v2.23.0 r/373
Merge commit '1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5' as 'third_party/git'
Diffstat (limited to 'third_party/git/t/t0002-gitfile.sh')
-rwxr-xr-xthird_party/git/t/t0002-gitfile.sh131
1 files changed, 131 insertions, 0 deletions
diff --git a/third_party/git/t/t0002-gitfile.sh b/third_party/git/t/t0002-gitfile.sh
new file mode 100755
index 0000000000..0aa9908ea1
--- /dev/null
+++ b/third_party/git/t/t0002-gitfile.sh
@@ -0,0 +1,131 @@
+#!/bin/sh
+
+test_description='.git file
+
+Verify that plumbing commands work when .git is a file
+'
+. ./test-lib.sh
+
+objpath() {
+	echo "$1" | sed -e 's|\(..\)|\1/|'
+}
+
+test_expect_success 'initial setup' '
+	REAL="$(pwd)/.real" &&
+	mv .git "$REAL"
+'
+
+test_expect_success 'bad setup: invalid .git file format' '
+	echo "gitdir $REAL" >.git &&
+	test_must_fail git rev-parse 2>.err &&
+	test_i18ngrep "invalid gitfile format" .err
+'
+
+test_expect_success 'bad setup: invalid .git file path' '
+	echo "gitdir: $REAL.not" >.git &&
+	test_must_fail git rev-parse 2>.err &&
+	test_i18ngrep "not a git repository" .err
+'
+
+test_expect_success 'final setup + check rev-parse --git-dir' '
+	echo "gitdir: $REAL" >.git &&
+	test "$REAL" = "$(git rev-parse --git-dir)"
+'
+
+test_expect_success 'check hash-object' '
+	echo "foo" >bar &&
+	SHA=$(cat bar | git hash-object -w --stdin) &&
+	test_path_is_file "$REAL/objects/$(objpath $SHA)"
+'
+
+test_expect_success 'check cat-file' '
+	git cat-file blob $SHA >actual &&
+	test_cmp bar actual
+'
+
+test_expect_success 'check update-index' '
+	test_path_is_missing "$REAL/index" &&
+	rm -f "$REAL/objects/$(objpath $SHA)" &&
+	git update-index --add bar &&
+	test_path_is_file "$REAL/index" &&
+	test_path_is_file "$REAL/objects/$(objpath $SHA)"
+'
+
+test_expect_success 'check write-tree' '
+	SHA=$(git write-tree) &&
+	test_path_is_file "$REAL/objects/$(objpath $SHA)"
+'
+
+test_expect_success 'check commit-tree' '
+	SHA=$(echo "commit bar" | git commit-tree $SHA) &&
+	test_path_is_file "$REAL/objects/$(objpath $SHA)"
+'
+
+test_expect_success 'check rev-list' '
+	echo $SHA >"$REAL/HEAD" &&
+	test "$SHA" = "$(git rev-list HEAD)"
+'
+
+test_expect_success 'setup_git_dir twice in subdir' '
+	git init sgd &&
+	(
+		cd sgd &&
+		git config alias.lsfi ls-files &&
+		mv .git .realgit &&
+		echo "gitdir: .realgit" >.git &&
+		mkdir subdir &&
+		cd subdir &&
+		>foo &&
+		git add foo &&
+		git lsfi >actual &&
+		echo foo >expected &&
+		test_cmp expected actual
+	)
+'
+
+test_expect_success 'enter_repo non-strict mode' '
+	test_create_repo enter_repo &&
+	(
+		cd enter_repo &&
+		test_tick &&
+		test_commit foo &&
+		mv .git .realgit &&
+		echo "gitdir: .realgit" >.git
+	) &&
+	head=$(git -C enter_repo rev-parse HEAD) &&
+	git ls-remote enter_repo >actual &&
+	cat >expected <<-EOF &&
+	$head	HEAD
+	$head	refs/heads/master
+	$head	refs/tags/foo
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'enter_repo linked checkout' '
+	(
+		cd enter_repo &&
+		git worktree add  ../foo refs/tags/foo
+	) &&
+	head=$(git -C enter_repo rev-parse HEAD) &&
+	git ls-remote foo >actual &&
+	cat >expected <<-EOF &&
+	$head	HEAD
+	$head	refs/heads/master
+	$head	refs/tags/foo
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'enter_repo strict mode' '
+	head=$(git -C enter_repo rev-parse HEAD) &&
+	git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
+	cat >expected <<-EOF &&
+	$head	HEAD
+	$head	refs/heads/master
+	$head	refs/tags/foo
+	EOF
+	test_cmp expected actual
+'
+
+test_done