git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel()
@ 2010-01-10  7:19 Steven Drake
  2010-01-10 10:11 ` Jonathan Nieder
  2010-01-11  7:23 ` Steven Drake
  0 siblings, 2 replies; 8+ messages in thread
From: Steven Drake @ 2010-01-10  7:19 UTC (permalink / raw)
  To: git

as it gives the absolute (aka "physical") path of the toplevel directory 
and 'cd -P' is not supported by all shell implementations.

See NetBSD PR/42168.
http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=42168
---
 git-sh-setup.sh |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index dfcb807..3cbec05 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -120,16 +120,10 @@ is_bare_repository () {
 }
 
 cd_to_toplevel () {
-	cdup=$(git rev-parse --show-cdup)
-	if test ! -z "$cdup"
+	if test ! -z "$(git rev-parse --show-cdup)"
 	then
-		# The "-P" option says to follow "physical" directory
-		# structure instead of following symbolic links.  When cdup is
-		# "../", this means following the ".." entry in the current
-		# directory instead textually removing a symlink path element
-		# from the PWD shell variable.  The "-P" behavior is more
-		# consistent with the C-style chdir used by most of Git.
-		cd -P "$cdup" || {
+		cdup=$(git rev-parse --show-toplevel)
+		cd "$cdup" || {
 			echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
 			exit 1
 		}
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH 1/2] Add 'git rev-parse --show-toplevel' option.
@ 2010-01-10  7:19 Steven Drake
  2010-01-11 22:34 ` [PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel() Steven Drake
  0 siblings, 1 reply; 8+ messages in thread
From: Steven Drake @ 2010-01-10  7:19 UTC (permalink / raw)
  To: git

 Shows the absolute path of the top-level working directory.
---
 Documentation/git-rev-parse.txt |    3 +++
 builtin-rev-parse.c             |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 82045a2..dc829b3 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -112,6 +112,9 @@ OPTIONS
 --remotes::
 	Show tag refs found in `$GIT_DIR/refs/remotes`.
 
+--show-toplevel::
+	Show the absolute path of the top-level directory.
+
 --show-prefix::
 	When the command is invoked from a subdirectory, show the
 	path of the current directory relative to the top-level
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 37d0233..96ab8bb 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -581,6 +581,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				for_each_remote_ref(show_reference, NULL);
 				continue;
 			}
+			if (!strcmp(arg, "--show-toplevel")) {
+				const char *work_tree = get_git_work_tree();
+				if (work_tree)
+					printf("%s\n", work_tree);
+				continue;
+			}
 			if (!strcmp(arg, "--show-prefix")) {
 				if (prefix)
 					puts(prefix);
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-01-11 22:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-10  7:19 [PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel() Steven Drake
2010-01-10 10:11 ` Jonathan Nieder
2010-01-11  7:12   ` Steven Drake
2010-01-11  7:23 ` Steven Drake
2010-01-11  7:46   ` Junio C Hamano
2010-01-11  9:02     ` Steven Drake
2010-01-11  9:58       ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2010-01-10  7:19 [PATCH 1/2] Add 'git rev-parse --show-toplevel' option Steven Drake
2010-01-11 22:34 ` [PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel() Steven Drake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).