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

[PATCH] rev-parse: --is-bare-repository option

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Mar 11, 2007, 15:05 UTC
Message-ID
<20070311150527.GA23224@moooo.ath.cx>
In-Reply-To
<fcaeb9bf0703110627r6500d621rf6710c58e9e8d65b@mail.gmail.com>
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> Um.. git-sh-setup.sh may need special treatment because its
> is_bare_directory doesn't call this function.
Here is rev-parse --is-bare-repository to fix this.
I'm not sure if git-sh-setup.sh:is_bare_repository should do other
checks if git-rev-parse --is-bare-repository fails.
---
 Documentation/git-rev-parse.txt |    7 +++++++
 builtin-rev-parse.c             |    5 +++++
 git-sh-setup.sh                 |    6 +-----
 git-svn.perl                    |    2 +-
 4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index ccc66aa..d024d93 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -89,6 +89,13 @@ OPTIONS
 --git-dir::
 	Show `$GIT_DIR` if defined else show the path to the .git directory.
 
+--is-inside-git-dir::
+	When the current working directory is below the repository
+	directory print "true", otherwise "false".
+
+--is-bare-repository::
+	When the repository is bare print "true", otherwise "false".
+
 --short, --short=number::
 	Instead of outputting the full SHA1 values of object names try to
 	abbreviate them to a shorter unique name. When no length is specified
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 37addb2..71d5162 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -352,6 +352,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 						: "false");
 				continue;
 			}
+			if (!strcmp(arg, "--is-bare-repository")) {
+				printf("%s\n", is_bare_repository() ? "true"
+						: "false");
+				continue;
+			}
 			if (!prefixcmp(arg, "--since=")) {
 				show_datestring("--max-age=", arg+8);
 				continue;
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index f24c7f2..9ac657a 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -29,11 +29,7 @@ set_reflog_action() {
 }
 
 is_bare_repository () {
-	git-config --bool --get core.bare ||
-	case "$GIT_DIR" in
-	.git | */.git) echo false ;;
-	*) echo true ;;
-	esac
+	git-rev-parse --is-bare-repository
 }
 
 cd_to_toplevel () {
diff --git a/git-svn.perl b/git-svn.perl
index 326e89f..ea5da95 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -559,7 +559,7 @@ sub post_fetch_checkout {
 	my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
 	return if -f $index;
 
-	chomp(my $bare = `git config --bool --get core.bare`);
+	chomp(my $bare = `git rev-parse --is-bare-repository`);
 	return if $bare eq 'true';
 	return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true';
 	command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
-- 
1.5.0.3.355.g8488f-dirty
Previous: Nguyen Thai Ngoc DuyNext: Matthias Lederhofer
Message 26 of 39 in “[RFC] introduce GIT_WORK_DIR environment variable”
  1. Matthias LederhoferMar 11, 2007
  2. Junio C HamanoMar 11, 2007
  3. Andy ParkinsMar 11, 2007
  4. Matthias LederhoferMar 11, 2007
  5. Junio C HamanoMar 11, 2007
  6. Johannes SchindelinMar 11, 2007
  7. Linus TorvaldsMar 11, 2007
  8. Junio C HamanoMar 11, 2007
  9. Linus TorvaldsMar 11, 2007
  10. A.J. RossiniMar 12, 2007
  11. Andy ParkinsApr 1, 2007
  12. Nguyen Thai Ngoc DuyMar 11, 2007
  13. Matthias LederhoferMar 11, 2007
  14. Nguyen Thai Ngoc DuyMar 11, 2007
  15. Matthias LederhoferMar 11, 2007
  16. Nguyen Thai Ngoc DuyMar 11, 2007
  17. introduce GIT_WORK_DIR environment variableMatthias Lederhofer, Mar 11, 2007
  18. Nguyen Thai Ngoc DuyMar 11, 2007
  19. use $GIT_DIR/workdir as working directory with $GIT_DIRMatthias Lederhofer, Mar 11, 2007
  20. core.workdir config variableMatthias Lederhofer, Mar 13, 2007
  21. core.workdir config variableMatthias Lederhofer, Mar 13, 2007
  22. Shawn O. PearceMar 14, 2007
  23. Junio C HamanoMar 14, 2007
  24. Shawn O. PearceMar 14, 2007
  25. Nguyen Thai Ngoc DuyMar 11, 2007
  26. rev-parse: --is-bare-repository optionMatthias Lederhofer, Mar 11, 2007
  27. git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is setMatthias Lederhofer, Mar 12, 2007
  28. Joshua N PritikinMar 12, 2007
  29. Matthias LederhoferMar 12, 2007
  30. Matthias LederhoferMar 12, 2007
  31. Nguyen Thai Ngoc DuyMar 12, 2007
  32. Matthias LederhoferMar 12, 2007
  33. Junio C HamanoMar 12, 2007
  34. Matthias LederhoferMar 12, 2007
  35. always interpret GIT_WORK_DIR relative to $GIT_DIRMatthias Lederhofer, Mar 12, 2007
  36. GIT_WORK_DIR: documentation for relative pathMatthias Lederhofer, Mar 12, 2007
  37. Junio C HamanoMar 12, 2007
  38. Matthias LederhoferMar 12, 2007
  39. git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is setMatthias Lederhofer, Mar 12, 2007

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.