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

[PATCH v2 8/8] gitk: show modified files with separate work tree

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
May 24, 2011, 02:44 UTC
Message-ID
<1306205048-9747-1-git-send-email-martin.von.zweigbergk@gmail.com>
In-Reply-To
<1301969659-19703-9-git-send-email-martin.von.zweigbergk@gmail.com>

"git rev-parse --is-inside-work-tree" is currently used to determine whether to show modified files in gitk (the red and green fake commits). This does not work if the current directory is not inside the work tree, as can be the case e.g. if GIT_WORK_TREE is set. Instead, check if the repository is not bare and that we are not inside the .git directory.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

The only change since v1 is that the hasworktree procedure has been simplified. I was conservative and left the recalculatation of hasworktree in updatecommits(). There are no changes to any of the other patches, so I didn't bother resending them. Sorry about the long delay for such a trivial fixup.

 gitk-git/gitk |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 10b2bca..01b63e5 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -9,6 +9,11 @@ exec wish "$0" -- "$@"
 
 package require Tk
 
+proc hasworktree {} {
+    return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
+		  [exec git rev-parse --is-inside-git-dir] == "false"}]
+}
+
 # A simple scheduler for compute-intensive stuff.
 # The aim is to make sure that event handlers for GUI actions can
 # run at least every 50-100 ms.  Unfortunately fileevent handlers are
@@ -459,11 +464,11 @@ proc updatecommits {} {
     global viewactive viewcomplete tclencoding
     global startmsecs showneartags showlocalchanges
     global mainheadid viewmainheadid viewmainheadid_orig pending_select
-    global isworktree
+    global hasworktree
     global varcid vposids vnegids vflags vrevs
     global show_notes
 
-    set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
+    set hasworktree [hasworktree]
     rereadrefs
     set view $curview
     if {$mainheadid ne $viewmainheadid_orig($view)} {
@@ -5026,9 +5031,9 @@ proc dohidelocalchanges {} {
 # spawn off a process to do git diff-index --cached HEAD
 proc dodiffindex {} {
     global lserial showlocalchanges vfilelimit curview
-    global isworktree
+    global hasworktree
 
-    if {!$showlocalchanges || !$isworktree} return
+    if {!$showlocalchanges || !$hasworktree} return
     incr lserial
     set cmd "|git diff-index --cached HEAD"
     if {$vfilelimit($curview) ne {}} {
@@ -11621,9 +11626,9 @@ set stopped 0
 set stuffsaved 0
 set patchnum 0
 set lserial 0
-set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
+set hasworktree [hasworktree]
 set cdup {}
-if {$isworktree} {
+if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
     set cdup [exec git rev-parse --show-cdup]
 }
 set worktree [exec git rev-parse --show-toplevel]
-- 
1.7.4.79.gcbe20
Previous: Junio C HamanoNext: Peter Baumann
Message 14 of 15 in “make gitk work better in non-top-level directory”
  1. 0/8 make gitk work better in non-top-level directoryMartin von Zweigbergk, Apr 5, 2011
  2. 1/8 gitk: fix file highlight when run in subdirectoryMartin von Zweigbergk, Apr 5, 2011
  3. Paul MackerrasApr 10, 2011
  4. Martin von ZweigbergkApr 10, 2011
  5. 2/8 gitk: fix "show origin of this line" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  6. 3/8 gitk: fix "blame parent commit" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  7. 4/8 gitk: fix "External diff" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  8. 5/8 gitk: put temporary directory inside .gitMartin von Zweigbergk, Apr 5, 2011
  9. 6/8 gitk: run 'git rev-parse --git-dir' only onceMartin von Zweigbergk, Apr 5, 2011
  10. 7/8 gitk: simplify calculation of gitdirMartin von Zweigbergk, Apr 5, 2011
  11. 8/8 gitk: show modified files with separate work treeMartin von Zweigbergk, Apr 5, 2011
  12. Paul MackerrasApr 10, 2011
  13. Junio C HamanoApr 11, 2011
  14. 8/8 gitk: show modified files with separate work treeMartin von Zweigbergk, May 24, 2011
  15. Peter BaumannApr 5, 2011

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.