From: Eric Sunshine Date: Fri, 05 Jun 2020 21:13:28 GMT Subject: Re: [PATCH] git-gui: allow opening work trees from the startup dialog Message-ID: In-Reply-To: <20200605204803.lbolbny5m5dczynn@yadavpratyush.com> On Fri, Jun 5, 2020 at 4:48 PM Pratyush Yadav wrote: > On 26/05/20 03:33PM, Mikhail Terekhov via GitGitGadget wrote: > > From: Mikhail Terekhov > > + 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.