git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-gui: allow opening work trees from the startup dialog
@ 2020-05-26 15:33 Mikhail Terekhov via GitGitGadget
  2020-06-05 20:48 ` Pratyush Yadav
  2020-06-06  4:33 ` [PATCH v2] " Mikhail Terekhov via GitGitGadget
  0 siblings, 2 replies; 6+ messages in thread
From: Mikhail Terekhov via GitGitGadget @ 2020-05-26 15:33 UTC (permalink / raw)
  To: git; +Cc: Mikhail Terekhov, Pratyush Yadav, Mikhail Terekhov

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.

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

 lib/choose_repository.tcl | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
index e54f3e66d8f..8f911e89fbb 100644
--- a/lib/choose_repository.tcl
+++ b/lib/choose_repository.tcl
@@ -362,8 +362,19 @@ proc _is_git {path {outdir_var ""}} {
 		gets $fp line
 		close $fp
 		if {[regexp "^gitdir: (.+)$" $line line link_target]} {
+			set check_path [file normalize $path]
 			set path [file join [file dirname $path] $link_target]
 			set path [file normalize $path]
+
+			if {[file exists [file join $path gitdir]]} {
+				set fp [open [file join $path gitdir] r]
+				gets $fp worktree_path
+				close $fp
+				if {[string equal $check_path $worktree_path]} {
+					set outdir $path
+					return 1
+				}
+			}
 		}
 	}
 

base-commit: c195247812f8cd38ba7e1c603112e6c1d8d8e71e
-- 
gitgitgadget

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

* Re: [PATCH] git-gui: allow opening work trees from the startup dialog
  2020-05-26 15:33 [PATCH] git-gui: allow opening work trees from the startup dialog Mikhail Terekhov via GitGitGadget
@ 2020-06-05 20:48 ` Pratyush Yadav
  2020-06-05 21:13   ` Eric Sunshine
  2020-06-06  4:33 ` [PATCH v2] " Mikhail Terekhov via GitGitGadget
  1 sibling, 1 reply; 6+ messages in thread
From: Pratyush Yadav @ 2020-06-05 20:48 UTC (permalink / raw)
  To: Mikhail Terekhov via GitGitGadget; +Cc: git, Mikhail Terekhov

Hi Mikhail,

Thanks for the patch.

On 26/05/20 03:33PM, 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.

IIUC, you are referring to work trees other than the main work tree, 
correct?

I tested my theory, and you are right. Applying this patch allows me to 
open git-gui in a worktree.
 
> 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.
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-644%2Ftermim%2Fgit-gui-open-worktree-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-644/termim/git-gui-open-worktree-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/644
> 
>  lib/choose_repository.tcl | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
> index e54f3e66d8f..8f911e89fbb 100644
> --- a/lib/choose_repository.tcl
> +++ b/lib/choose_repository.tcl
> @@ -362,8 +362,19 @@ proc _is_git {path {outdir_var ""}} {
>  		gets $fp line
>  		close $fp
>  		if {[regexp "^gitdir: (.+)$" $line line link_target]} {
> +			set check_path [file normalize $path]
>  			set path [file join [file dirname $path] $link_target]
>  			set path [file normalize $path]
> +

This should have a comment explaining we are checking for a worktree. 
Will add it locally.

> +			if {[file exists [file join $path gitdir]]} {
> +				set fp [open [file join $path gitdir] r]
> +				gets $fp worktree_path
> +				close $fp
> +				if {[string equal $check_path $worktree_path]} {
> +					set outdir $path
> +					return 1
> +				}
> +			}

I wonder if there is a way of finding if the path is a worktree path 
using a Git plumbing command. That IMO would be better than rolling our 
own logic to check if something is a worktree.

I'll check once if I can figure something out (you do that too if you 
can). Otherwise I'll merge it in. Thanks.

-- 
Regards,
Pratyush Yadav

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

* Re: [PATCH] git-gui: allow opening work trees from the startup dialog
  2020-06-05 20:48 ` Pratyush Yadav
@ 2020-06-05 21:13   ` Eric Sunshine
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Sunshine @ 2020-06-05 21:13 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: Mikhail Terekhov via GitGitGadget, Git List, Mikhail Terekhov

On Fri, Jun 5, 2020 at 4:48 PM Pratyush Yadav <me@yadavpratyush.com> wrote:
> On 26/05/20 03:33PM, Mikhail Terekhov via GitGitGadget wrote:
> > From: Mikhail Terekhov <termim@gmail.com>
> > +                     if {[file exists [file join $path gitdir]]} {
> > +                             set fp [open [file join $path gitdir] r]
> > +                             gets $fp worktree_path
> > +                             close $fp
> > +                             if {[string equal $check_path $worktree_path]} {
> > +                                     set outdir $path
> > +                                     return 1
> > +                             }
> > +                     }
>
> I wonder if there is a way of finding if the path is a worktree path
> using a Git plumbing command. That IMO would be better than rolling our
> own logic to check if something is a worktree.

Perhaps use:

    (cd "$path" && git rev-parse --is-inside-work-tree)

That will return "true" for both the main worktree and a linked
worktree. You may need to suppress stderr if you expect to run the
command in an arbitrary directory since it will error out if the
directory is not under Git's control.

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

* [PATCH v2] git-gui: allow opening work trees from the startup dialog
  2020-05-26 15:33 [PATCH] git-gui: allow opening work trees from the startup dialog Mikhail Terekhov via GitGitGadget
  2020-06-05 20:48 ` Pratyush Yadav
@ 2020-06-06  4:33 ` Mikhail Terekhov via GitGitGadget
  2020-06-08  9:31   ` Pratyush Yadav
  1 sibling, 1 reply; 6+ messages in thread
From: Mikhail Terekhov via GitGitGadget @ 2020-06-06  4:33 UTC (permalink / raw)
  To: git; +Cc: Mikhail Terekhov, Pratyush Yadav, Mikhail Terekhov

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(-)

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} {

base-commit: c195247812f8cd38ba7e1c603112e6c1d8d8e71e
-- 
gitgitgadget

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

* Re: [PATCH v2] git-gui: allow opening work trees from the startup dialog
  2020-06-06  4:33 ` [PATCH v2] " Mikhail Terekhov via GitGitGadget
@ 2020-06-08  9:31   ` Pratyush Yadav
  2020-06-22 14:58     ` Pratyush Yadav
  0 siblings, 1 reply; 6+ messages in thread
From: Pratyush Yadav @ 2020-06-08  9:31 UTC (permalink / raw)
  To: Mikhail Terekhov via GitGitGadget; +Cc: git, Mikhail Terekhov, Eric Sunshine

+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

-- 
Regards,
Pratyush Yadav

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

* Re: [PATCH v2] git-gui: allow opening work trees from the startup dialog
  2020-06-08  9:31   ` Pratyush Yadav
@ 2020-06-22 14:58     ` Pratyush Yadav
  0 siblings, 0 replies; 6+ messages in thread
From: Pratyush Yadav @ 2020-06-22 14:58 UTC (permalink / raw)
  To: Mikhail Terekhov via GitGitGadget; +Cc: git, Mikhail Terekhov, Eric Sunshine

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.

-- 
Regards,
Pratyush Yadav

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

end of thread, other threads:[~2020-06-22 14:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 15:33 [PATCH] git-gui: allow opening work trees from the startup dialog Mikhail Terekhov via GitGitGadget
2020-06-05 20:48 ` Pratyush Yadav
2020-06-05 21:13   ` Eric Sunshine
2020-06-06  4:33 ` [PATCH v2] " Mikhail Terekhov via GitGitGadget
2020-06-08  9:31   ` Pratyush Yadav
2020-06-22 14:58     ` Pratyush Yadav

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).