[v2] git-gui: allow opening work trees from the startup dialog
diff mbox series

Message ID pull.644.v2.git.1591418019023.gitgitgadget@gmail.com
State New
Headers show
Series
  • [v2] git-gui: allow opening work trees from the startup dialog
Related show

Commit Message

Han-Wen Nienhuys via GitGitGadget June 6, 2020, 4:33 a.m. UTC
From: Mikhail Terekhov <termim@gmail.com>

In proc _is_git check that supplied path is a valid work tree path.
This allows the choose_repository::pick dialog to accept path to a
work tree directory.

Signed-off-by: Mikhail Terekhov <termim@gmail.com>
---
    git-gui: allow opening work trees from the startup dialog
    
    Trying to open a working tree from the "Open Existing Repository" link
    of the git-gui startup dialog results in an error: Not a Git repository:
    .... This patch fixes that error.
    
    Changes since v1:
    
     * Use git rev-parse instead of rolling our own logic to check if
       something is a worktree as suggested by Pratyush Yadav 
       me@yadavpratyush.com [me@yadavpratyush.com] and Eric Sunshine 
       sunshine@sunshineco.com [sunshine@sunshineco.com].

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-644%2Ftermim%2Fgit-gui-open-worktree-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-644/termim/git-gui-open-worktree-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/644

Range-diff vs v1:

 1:  ca55ec3adb4 < -:  ----------- git-gui: allow opening work trees from the startup dialog
 -:  ----------- > 1:  c3b378fe397 git-gui: allow opening work trees from the startup dialog


 lib/choose_repository.tcl | 29 +++++------------------------
 1 file changed, 5 insertions(+), 24 deletions(-)


base-commit: c195247812f8cd38ba7e1c603112e6c1d8d8e71e

Comments

Pratyush Yadav June 8, 2020, 9:31 a.m. UTC | #1
+Cc Eric.

On 06/06/20 04:33AM, Mikhail Terekhov via GitGitGadget wrote:
> From: Mikhail Terekhov <termim@gmail.com>
> 
> In proc _is_git check that supplied path is a valid work tree path.
> This allows the choose_repository::pick dialog to accept path to a
> work tree directory.
> 
> Signed-off-by: Mikhail Terekhov <termim@gmail.com>
> ---
>  lib/choose_repository.tcl | 29 +++++------------------------
>  1 file changed, 5 insertions(+), 24 deletions(-)
> 
> diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
> index e54f3e66d8f..07f29b0b13b 100644
> --- a/lib/choose_repository.tcl
> +++ b/lib/choose_repository.tcl
> @@ -357,31 +357,12 @@ proc _is_git {path {outdir_var ""}} {
>  	if {$outdir_var ne ""} {
>  		upvar 1 $outdir_var outdir
>  	}
> -	if {[file isfile $path]} {
> -		set fp [open $path r]
> -		gets $fp line
> -		close $fp
> -		if {[regexp "^gitdir: (.+)$" $line line link_target]} {
> -			set path [file join [file dirname $path] $link_target]
> -			set path [file normalize $path]
> -		}
> -	}
> -
> -	if {[file exists [file join $path HEAD]]
> -	 && [file exists [file join $path objects]]
> -	 && [file exists [file join $path config]]} {
> -		set outdir $path
> -		return 1
> -	}
> -	if {[is_Cygwin]} {
> -		if {[file exists [file join $path HEAD]]
> -		 && [file exists [file join $path objects.lnk]]
> -		 && [file exists [file join $path config.lnk]]} {
> -			set outdir $path
> -			return 1
> -		}
> +	if {[catch { 
> +		set outdir [git rev-parse --resolve-git-dir $path] 
> +		} ]} {
> +			return 0

I fixed trailing whitespace in a couple lines and a small style nitpick. You 
can check them here [0]. Will merge. Thanks both.

[0] https://github.com/prati0100/git-gui/commit/79089e52643ce1ba7d8494f32b2fb1891c926079
Pratyush Yadav June 22, 2020, 2:58 p.m. UTC | #2
On 08/06/20 03:01PM, Pratyush Yadav wrote:
> +Cc Eric.
> 
> On 06/06/20 04:33AM, Mikhail Terekhov via GitGitGadget wrote:
> > From: Mikhail Terekhov <termim@gmail.com>
> > 
> > In proc _is_git check that supplied path is a valid work tree path.
> > This allows the choose_repository::pick dialog to accept path to a
> > work tree directory.
> > 
> > Signed-off-by: Mikhail Terekhov <termim@gmail.com>
> > ---
> >  lib/choose_repository.tcl | 29 +++++------------------------
> >  1 file changed, 5 insertions(+), 24 deletions(-)
> > 
> > diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
> > index e54f3e66d8f..07f29b0b13b 100644
> > --- a/lib/choose_repository.tcl
> > +++ b/lib/choose_repository.tcl
> > @@ -357,31 +357,12 @@ proc _is_git {path {outdir_var ""}} {
> >  	if {$outdir_var ne ""} {
> >  		upvar 1 $outdir_var outdir
> >  	}
> > -	if {[file isfile $path]} {
> > -		set fp [open $path r]
> > -		gets $fp line
> > -		close $fp
> > -		if {[regexp "^gitdir: (.+)$" $line line link_target]} {
> > -			set path [file join [file dirname $path] $link_target]
> > -			set path [file normalize $path]
> > -		}
> > -	}
> > -
> > -	if {[file exists [file join $path HEAD]]
> > -	 && [file exists [file join $path objects]]
> > -	 && [file exists [file join $path config]]} {
> > -		set outdir $path
> > -		return 1
> > -	}
> > -	if {[is_Cygwin]} {
> > -		if {[file exists [file join $path HEAD]]
> > -		 && [file exists [file join $path objects.lnk]]
> > -		 && [file exists [file join $path config.lnk]]} {
> > -			set outdir $path
> > -			return 1
> > -		}
> > +	if {[catch { 
> > +		set outdir [git rev-parse --resolve-git-dir $path] 
> > +		} ]} {
> > +			return 0
> 
> I fixed trailing whitespace in a couple lines and a small style nitpick. You 
> can check them here [0]. Will merge. Thanks both.
> 
> [0] https://github.com/prati0100/git-gui/commit/79089e52643ce1ba7d8494f32b2fb1891c926079

Merged to git-gui/master.

Patch
diff mbox series

diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
index e54f3e66d8f..07f29b0b13b 100644
--- a/lib/choose_repository.tcl
+++ b/lib/choose_repository.tcl
@@ -357,31 +357,12 @@  proc _is_git {path {outdir_var ""}} {
 	if {$outdir_var ne ""} {
 		upvar 1 $outdir_var outdir
 	}
-	if {[file isfile $path]} {
-		set fp [open $path r]
-		gets $fp line
-		close $fp
-		if {[regexp "^gitdir: (.+)$" $line line link_target]} {
-			set path [file join [file dirname $path] $link_target]
-			set path [file normalize $path]
-		}
-	}
-
-	if {[file exists [file join $path HEAD]]
-	 && [file exists [file join $path objects]]
-	 && [file exists [file join $path config]]} {
-		set outdir $path
-		return 1
-	}
-	if {[is_Cygwin]} {
-		if {[file exists [file join $path HEAD]]
-		 && [file exists [file join $path objects.lnk]]
-		 && [file exists [file join $path config.lnk]]} {
-			set outdir $path
-			return 1
-		}
+	if {[catch { 
+		set outdir [git rev-parse --resolve-git-dir $path] 
+		} ]} {
+			return 0
 	}
-	return 0
+	return 1
 }
 
 proc _objdir {path} {