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

Re: [PATCH] git-gui: allow opening work trees from the startup dialog

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Jun 5, 2020, 20:48 UTC
Message-ID
<20200605204803.lbolbny5m5dczynn@yadavpratyush.com>
In-Reply-To
<pull.644.git.1590507201474.gitgitgadget@gmail.com>
Hi Mikhail,
Thanks for the patch.
On 26/05/20 03:33PM, Mikhail Terekhov via GitGitGadget wrote:
Show 5 quoted lines
> 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.
 
Show 27 quoted lines
> 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.

Show 9 quoted lines
> +			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
Previous: Mikhail Terekhov via GitGitGadgetNext: Eric Sunshine
Message 2 of 6 in “git-gui: allow opening work trees from the startup dialog”
  1. git-gui: allow opening work trees from the startup dialogMikhail Terekhov via GitGitGadget, May 26, 2020
  2. Pratyush YadavJun 5, 2020
  3. Eric SunshineJun 5, 2020
  4. git-gui: allow opening work trees from the startup dialogMikhail Terekhov via GitGitGadget, Jun 6, 2020
  5. Pratyush YadavJun 8, 2020
  6. Pratyush YadavJun 22, 2020

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.