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

[PATCHv4 3/5] git-gui: work from the .git dir

From
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date
Jan 23, 2010, 10:03 UTC
Message-ID
<1264241018-6616-4-git-send-email-giuseppe.bilotta@gmail.com>
In-Reply-To
<1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com>

When git-gui is run from a .git dir, _gitdir would be set to "." by rev-parse, something that confuses the worktree detection.

Fix by expanding the value of _gitdir to pwd in this special case.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 git-gui/git-gui.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index d0dff40..c5c787d 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -1102,6 +1102,8 @@ if {[catch {
 		set _prefix {}
 		}]
 	&& [catch {
+		# beware that from the .git dir this sets _gitdir to .
+		# and _prefix to the empty string
 		set _gitdir [git rev-parse --git-dir]
 		set _prefix [git rev-parse --show-prefix]
 	} err]} {
@@ -1110,6 +1112,14 @@ if {[catch {
 	choose_repository::pick
 	set picked 1
 }
+
+# we expand the _gitdir when it's just a single dot (i.e. when we're being
+# run from the .git dir itself) lest the routines to find the worktree
+# get confused
+if {$_gitdir eq "."} {
+	set _gitdir [pwd]
+}
+
 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
 	catch {set _gitdir [exec cygpath --windows $_gitdir]}
 }
-- 
1.6.6.rc1.295.g3a4e71
Previous: Giuseppe BilottaNext: Giuseppe Bilotta
Message 4 of 9 in “[PATCHv4 0/5] git-gui: more robust handling of fancy repos”
  1. Giuseppe BilottaJan 23, 2010
  2. 1/5 git-gui: handle non-standard worktree locationsGiuseppe Bilotta, Jan 23, 2010
  3. 2/5 git-gui: handle bare repos correctlyGiuseppe Bilotta, Jan 23, 2010
  4. 3/5 git-gui: work from the .git dirGiuseppe Bilotta, Jan 23, 2010
  5. 4/5 git-gui: set GIT_DIR and GIT_WORK_TREE after setupGiuseppe Bilotta, Jan 23, 2010
  6. Shawn O. PearceJan 23, 2010
  7. git-gui: set GIT_DIR and GIT_WORK_TREE after setupGiuseppe Bilotta, Jan 23, 2010
  8. Shawn O. PearceJan 24, 2010
  9. 5/5 git-gui: update shortcut tools to use _gitworktreeGiuseppe Bilotta, Jan 23, 2010

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.