git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: David Kastrup <dak@gnu.org>
Cc: git@vger.kernel.org
Subject: Re: Problem with git-gui and relative directories
Date: Fri, 24 Aug 2007 23:18:35 -0400	[thread overview]
Message-ID: <20070825031834.GW27913@spearce.org> (raw)
In-Reply-To: <868x81vynk.fsf@lola.quinscape.zz>

David Kastrup <dak@gnu.org> wrote:
> Doing something like
...
> errors out with
> 
> fatal: cannot stat path woozle/plop: No such file or directory
> 
> Obviously, git-gui is confused about relative paths here.

Yes, it is.  I'm committing this, to be included in 0.8.2:

-->8--
git-gui: Correct 'git gui blame' in a subdirectory

David Kastrup pointed out that the following sequence was not
working as we had intended:

  $ cd lib
  $ git gui blame console.tcl
  fatal: cannot stat path lib/console.tcl: No such file or directory

The problem here was we disabled the chdir to the root of the
working tree when we are running with a "bare allowed" feature
such as blame or browser, but we still kept the prefix we found via
`git rev-parse --show-prefix`.  This caused us to try and look for
the file "console.tcl" within the subdirectory but also include
the subdirectory's own path from the root of the working tree.
This is unlikely to succeed, unless the user just happened to have
a "lib/lib/console.tcl" file in the repository, in which case we
would produce the wrong result.

In the case of a bare repository we shouldn't get back a value from
`rev-parse --show-prefix`, so really $_prefix should only be set
to the non-empty string if we are in a working tree and we are in a
subdirectory of that working tree.  If this is true we really want
to always be at the top level of the working tree, as all paths are
accessed as though they were relative to the top of the working tree.
Converting $_prefix to a ../ sequence is a fairly simple approach
to moving up the requisite levels.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 743b7d4..fa30ccc 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -703,7 +703,15 @@ if {![file isdirectory $_gitdir]} {
 	error_popup "Git directory not found:\n\n$_gitdir"
 	exit 1
 }
-if {![is_enabled bare]} {
+if {$_prefix ne {}} {
+	regsub -all {[^/]+/} $_prefix ../ cdup
+	if {[catch {cd $cdup} err]} {
+		catch {wm withdraw .}
+		error_popup "Cannot move to top of working directory:\n\n$err"
+		exit 1
+	}
+	unset cdup
+} elseif {![is_enabled bare]} {
 	if {[lindex [file split $_gitdir] end] ne {.git}} {
 		catch {wm withdraw .}
 		error_popup "Cannot use funny .git directory:\n\n$_gitdir"
-- 
1.5.3.rc6.17.g1911

-- 
Shawn.

  reply	other threads:[~2007-08-25  3:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-24 13:40 Problem with git-gui and relative directories David Kastrup
2007-08-25  3:18 ` Shawn O. Pearce [this message]
2007-08-25  7:26   ` David Kastrup
2007-08-25  8:15     ` Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070825031834.GW27913@spearce.org \
    --to=spearce@spearce.org \
    --cc=dak@gnu.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).