git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] t1515: add tests for rev-parse out-of-repo helpers

From
Jeff King <peff@peff.net>
Date
Feb 26, 2016, 23:26 UTC
Message-ID
<20160226232632.GA9552@sigill.intra.peff.net>
In-Reply-To
<20160226232507.GA9404@sigill.intra.peff.net>

The git-rev-parse command is a dumping ground for helpers that let scripts make various queries of git. Many of these are conceptually independent of being inside a git repository.

With the exception of --parseopt, we do not directly test most of these features in our test suite. Let's give them some basic sanity checks, which reveals that some of them have been broken for some time when run from outside a repository.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t1515-rev-parse-outside-repo.sh | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 t/t1515-rev-parse-outside-repo.sh
diff --git a/t/t1515-rev-parse-outside-repo.sh b/t/t1515-rev-parse-outside-repo.sh
new file mode 100755
index 0000000..ae33093
--- /dev/null
+++ b/t/t1515-rev-parse-outside-repo.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+test_description='check that certain rev-parse options work outside repo'
+. ./test-lib.sh
+
+test_expect_success 'set up non-repo directory' '
+	GIT_CEILING_DIRECTORIES=$(pwd) &&
+	export GIT_CEILING_DIRECTORIES &&
+	mkdir non-repo &&
+	cd non-repo &&
+	# confirm that git does not find a repo
+	test_must_fail git rev-parse --git-dir
+'
+
+# Rather than directly test the output of sq-quote directly,
+# make sure the shell can read back a tricky case, since
+# that's what we really care about anyway.
+tricky="really tricky with \\ and \" and '"
+dump_args () {
+	for i in "$@"; do
+		echo "arg: $i"
+	done
+}
+test_expect_success 'rev-parse --sq-quote' '
+	dump_args "$tricky" easy >expect &&
+	eval "dump_args $(git rev-parse --sq-quote "$tricky" easy)" >actual &&
+	test_cmp expect actual
+'
+
+test_expect_failure 'rev-parse --local-env-vars' '
+	git rev-parse --local-env-vars >actual &&
+	# we do not want to depend on the complete list here,
+	# so just look for something plausible
+	grep ^GIT_DIR actual
+'
+
+test_expect_failure 'rev-parse --resolve-git-dir' '
+	git init --separate-git-dir repo dir &&
+	test_must_fail git rev-parse --resolve-git-dir . &&
+	echo "$(pwd)/repo" >expect &&
+	git rev-parse --resolve-git-dir dir/.git >actual &&
+	test_cmp expect actual
+'
+
+test_done
-- 
2.7.2.767.g705917e
Previous: Jeff KingNext: Jeff King
Message 2 of 13 in “fix some rev-parse options in non-repos”
  1. 0/2 fix some rev-parse options in non-reposJeff King, Feb 26, 2016
  2. 1/2 t1515: add tests for rev-parse out-of-repo helpersJeff King, Feb 26, 2016
  3. 2/2 Revert "rev-parse: remove restrictions on some options"Jeff King, Feb 26, 2016
  4. Jeff KingFeb 26, 2016
  5. Junio C HamanoFeb 26, 2016
  6. Jeff KingFeb 27, 2016
  7. Jeff KingFeb 29, 2016
  8. Junio C HamanoFeb 29, 2016
  9. Jeff KingFeb 29, 2016
  10. John KeepingFeb 27, 2016
  11. Jeff KingFeb 29, 2016
  12. Eric SunshineFeb 28, 2016
  13. Jeff KingFeb 29, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.