{"thread":{"id":"53550","subject":"[PATCH] git-gui: allow opening work trees from the startup dialog","startedAt":"2020-05-26T15:33:26Z","lastAt":"2020-06-22T14:58:44Z","messageCount":6,"participants":["Mikhail Terekhov via GitGitGadget","Pratyush Yadav","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"398580","messageId":"pull.644.git.1590507201474.gitgitgadget@gmail.com","threadId":"53550","inReplyTo":null,"subject":"[PATCH] git-gui: allow opening work trees from the startup dialog","fromName":"Mikhail Terekhov via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-05-26T15:33:21Z","receivedAt":"2020-05-26T15:33:26Z","isPatch":true,"sender":{"key":"name:Mikhail Terekhov","avatar":null},"body":"From: Mikhail Terekhov <termim@gmail.com>\n\nIn proc _is_git check that supplied path is a valid work tree path.\nThis allows the choose_repository::pick dialog to accept path to a\nwork tree directory.\n\nSigned-off-by: Mikhail Terekhov <termim@gmail.com>\n---\n    git-gui: allow opening work trees from the startup dialog\n    \n    Trying to open a working tree from the \"Open Existing Repository\" link\n    of the git-gui startup dialog results in an error: Not a Git repository:\n    .... This patch fixes that error.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-644%2Ftermim%2Fgit-gui-open-worktree-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-644/termim/git-gui-open-worktree-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/644\n\n lib/choose_repository.tcl | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl\nindex e54f3e66d8f..8f911e89fbb 100644\n--- a/lib/choose_repository.tcl\n+++ b/lib/choose_repository.tcl\n@@ -362,8 +362,19 @@ proc _is_git {path {outdir_var \"\"}} {\n \t\tgets $fp line\n \t\tclose $fp\n \t\tif {[regexp \"^gitdir: (.+)$\" $line line link_target]} {\n+\t\t\tset check_path [file normalize $path]\n \t\t\tset path [file join [file dirname $path] $link_target]\n \t\t\tset path [file normalize $path]\n+\n+\t\t\tif {[file exists [file join $path gitdir]]} {\n+\t\t\t\tset fp [open [file join $path gitdir] r]\n+\t\t\t\tgets $fp worktree_path\n+\t\t\t\tclose $fp\n+\t\t\t\tif {[string equal $check_path $worktree_path]} {\n+\t\t\t\t\tset outdir $path\n+\t\t\t\t\treturn 1\n+\t\t\t\t}\n+\t\t\t}\n \t\t}\n \t}\n \n\nbase-commit: c195247812f8cd38ba7e1c603112e6c1d8d8e71e\n-- \ngitgitgadget\n"},{"id":"399213","messageId":"20200605204803.lbolbny5m5dczynn@yadavpratyush.com","threadId":"53550","inReplyTo":"pull.644.git.1590507201474.gitgitgadget@gmail.com","subject":"Re: [PATCH] git-gui: allow opening work trees from the startup dialog","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-06-05T20:48:03Z","receivedAt":"2020-06-05T20:48:11Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"Hi Mikhail,\n\nThanks for the patch.\n\nOn 26/05/20 03:33PM, Mikhail Terekhov via GitGitGadget wrote:\n> From: Mikhail Terekhov <termim@gmail.com>\n> \n> In proc _is_git check that supplied path is a valid work tree path.\n> This allows the choose_repository::pick dialog to accept path to a\n> work tree directory.\n\nIIUC, you are referring to work trees other than the main work tree, \ncorrect?\n\nI tested my theory, and you are right. Applying this patch allows me to \nopen git-gui in a worktree.\n \n> Signed-off-by: Mikhail Terekhov <termim@gmail.com>\n> ---\n>     git-gui: allow opening work trees from the startup dialog\n>     \n>     Trying to open a working tree from the \"Open Existing Repository\" link\n>     of the git-gui startup dialog results in an error: Not a Git repository:\n>     .... This patch fixes that error.\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-644%2Ftermim%2Fgit-gui-open-worktree-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-644/termim/git-gui-open-worktree-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/644\n> \n>  lib/choose_repository.tcl | 11 +++++++++++\n>  1 file changed, 11 insertions(+)\n> \n> diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl\n> index e54f3e66d8f..8f911e89fbb 100644\n> --- a/lib/choose_repository.tcl\n> +++ b/lib/choose_repository.tcl\n> @@ -362,8 +362,19 @@ proc _is_git {path {outdir_var \"\"}} {\n>  \t\tgets $fp line\n>  \t\tclose $fp\n>  \t\tif {[regexp \"^gitdir: (.+)$\" $line line link_target]} {\n> +\t\t\tset check_path [file normalize $path]\n>  \t\t\tset path [file join [file dirname $path] $link_target]\n>  \t\t\tset path [file normalize $path]\n> +\n\nThis should have a comment explaining we are checking for a worktree. \nWill add it locally.\n\n> +\t\t\tif {[file exists [file join $path gitdir]]} {\n> +\t\t\t\tset fp [open [file join $path gitdir] r]\n> +\t\t\t\tgets $fp worktree_path\n> +\t\t\t\tclose $fp\n> +\t\t\t\tif {[string equal $check_path $worktree_path]} {\n> +\t\t\t\t\tset outdir $path\n> +\t\t\t\t\treturn 1\n> +\t\t\t\t}\n> +\t\t\t}\n\nI wonder if there is a way of finding if the path is a worktree path \nusing a Git plumbing command. That IMO would be better than rolling our \nown logic to check if something is a worktree.\n\nI'll check once if I can figure something out (you do that too if you \ncan). Otherwise I'll merge it in. Thanks.\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"399214","messageId":"CAPig+cQhm7XwKEJdjzmaG_gbOJZp1RbktJBeC0d8vTQfgLbydQ@mail.gmail.com","threadId":"53550","inReplyTo":"20200605204803.lbolbny5m5dczynn@yadavpratyush.com","subject":"Re: [PATCH] git-gui: allow opening work trees from the startup dialog","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-06-05T21:13:28Z","receivedAt":"2020-06-05T21:13:43Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Jun 5, 2020 at 4:48 PM Pratyush Yadav <me@yadavpratyush.com> wrote:\n> On 26/05/20 03:33PM, Mikhail Terekhov via GitGitGadget wrote:\n> > From: Mikhail Terekhov <termim@gmail.com>\n> > +                     if {[file exists [file join $path gitdir]]} {\n> > +                             set fp [open [file join $path gitdir] r]\n> > +                             gets $fp worktree_path\n> > +                             close $fp\n> > +                             if {[string equal $check_path $worktree_path]} {\n> > +                                     set outdir $path\n> > +                                     return 1\n> > +                             }\n> > +                     }\n>\n> I wonder if there is a way of finding if the path is a worktree path\n> using a Git plumbing command. That IMO would be better than rolling our\n> own logic to check if something is a worktree.\n\nPerhaps use:\n\n    (cd \"$path\" && git rev-parse --is-inside-work-tree)\n\nThat will return \"true\" for both the main worktree and a linked\nworktree. You may need to suppress stderr if you expect to run the\ncommand in an arbitrary directory since it will error out if the\ndirectory is not under Git's control.\n"},{"id":"399228","messageId":"pull.644.v2.git.1591418019023.gitgitgadget@gmail.com","threadId":"53550","inReplyTo":"pull.644.git.1590507201474.gitgitgadget@gmail.com","subject":"[PATCH v2] git-gui: allow opening work trees from the startup dialog","fromName":"Mikhail Terekhov via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-06T04:33:38Z","receivedAt":"2020-06-06T04:33:44Z","isPatch":true,"sender":{"key":"name:Mikhail Terekhov","avatar":null},"body":"From: Mikhail Terekhov <termim@gmail.com>\n\nIn proc _is_git check that supplied path is a valid work tree path.\nThis allows the choose_repository::pick dialog to accept path to a\nwork tree directory.\n\nSigned-off-by: Mikhail Terekhov <termim@gmail.com>\n---\n    git-gui: allow opening work trees from the startup dialog\n    \n    Trying to open a working tree from the \"Open Existing Repository\" link\n    of the git-gui startup dialog results in an error: Not a Git repository:\n    .... This patch fixes that error.\n    \n    Changes since v1:\n    \n     * Use git rev-parse instead of rolling our own logic to check if\n       something is a worktree as suggested by Pratyush Yadav \n       me@yadavpratyush.com [me@yadavpratyush.com] and Eric Sunshine \n       sunshine@sunshineco.com [sunshine@sunshineco.com].\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-644%2Ftermim%2Fgit-gui-open-worktree-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-644/termim/git-gui-open-worktree-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/644\n\nRange-diff vs v1:\n\n 1:  ca55ec3adb4 < -:  ----------- git-gui: allow opening work trees from the startup dialog\n -:  ----------- > 1:  c3b378fe397 git-gui: allow opening work trees from the startup dialog\n\n\n lib/choose_repository.tcl | 29 +++++------------------------\n 1 file changed, 5 insertions(+), 24 deletions(-)\n\ndiff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl\nindex e54f3e66d8f..07f29b0b13b 100644\n--- a/lib/choose_repository.tcl\n+++ b/lib/choose_repository.tcl\n@@ -357,31 +357,12 @@ proc _is_git {path {outdir_var \"\"}} {\n \tif {$outdir_var ne \"\"} {\n \t\tupvar 1 $outdir_var outdir\n \t}\n-\tif {[file isfile $path]} {\n-\t\tset fp [open $path r]\n-\t\tgets $fp line\n-\t\tclose $fp\n-\t\tif {[regexp \"^gitdir: (.+)$\" $line line link_target]} {\n-\t\t\tset path [file join [file dirname $path] $link_target]\n-\t\t\tset path [file normalize $path]\n-\t\t}\n-\t}\n-\n-\tif {[file exists [file join $path HEAD]]\n-\t && [file exists [file join $path objects]]\n-\t && [file exists [file join $path config]]} {\n-\t\tset outdir $path\n-\t\treturn 1\n-\t}\n-\tif {[is_Cygwin]} {\n-\t\tif {[file exists [file join $path HEAD]]\n-\t\t && [file exists [file join $path objects.lnk]]\n-\t\t && [file exists [file join $path config.lnk]]} {\n-\t\t\tset outdir $path\n-\t\t\treturn 1\n-\t\t}\n+\tif {[catch { \n+\t\tset outdir [git rev-parse --resolve-git-dir $path] \n+\t\t} ]} {\n+\t\t\treturn 0\n \t}\n-\treturn 0\n+\treturn 1\n }\n \n proc _objdir {path} {\n\nbase-commit: c195247812f8cd38ba7e1c603112e6c1d8d8e71e\n-- \ngitgitgadget\n"},{"id":"399285","messageId":"20200608093118.ppwpydlkd5bmsjh5@yadavpratyush.com","threadId":"53550","inReplyTo":"pull.644.v2.git.1591418019023.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] git-gui: allow opening work trees from the startup dialog","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-06-08T09:31:18Z","receivedAt":"2020-06-08T09:31:26Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"+Cc Eric.\n\nOn 06/06/20 04:33AM, Mikhail Terekhov via GitGitGadget wrote:\n> From: Mikhail Terekhov <termim@gmail.com>\n> \n> In proc _is_git check that supplied path is a valid work tree path.\n> This allows the choose_repository::pick dialog to accept path to a\n> work tree directory.\n> \n> Signed-off-by: Mikhail Terekhov <termim@gmail.com>\n> ---\n>  lib/choose_repository.tcl | 29 +++++------------------------\n>  1 file changed, 5 insertions(+), 24 deletions(-)\n> \n> diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl\n> index e54f3e66d8f..07f29b0b13b 100644\n> --- a/lib/choose_repository.tcl\n> +++ b/lib/choose_repository.tcl\n> @@ -357,31 +357,12 @@ proc _is_git {path {outdir_var \"\"}} {\n>  \tif {$outdir_var ne \"\"} {\n>  \t\tupvar 1 $outdir_var outdir\n>  \t}\n> -\tif {[file isfile $path]} {\n> -\t\tset fp [open $path r]\n> -\t\tgets $fp line\n> -\t\tclose $fp\n> -\t\tif {[regexp \"^gitdir: (.+)$\" $line line link_target]} {\n> -\t\t\tset path [file join [file dirname $path] $link_target]\n> -\t\t\tset path [file normalize $path]\n> -\t\t}\n> -\t}\n> -\n> -\tif {[file exists [file join $path HEAD]]\n> -\t && [file exists [file join $path objects]]\n> -\t && [file exists [file join $path config]]} {\n> -\t\tset outdir $path\n> -\t\treturn 1\n> -\t}\n> -\tif {[is_Cygwin]} {\n> -\t\tif {[file exists [file join $path HEAD]]\n> -\t\t && [file exists [file join $path objects.lnk]]\n> -\t\t && [file exists [file join $path config.lnk]]} {\n> -\t\t\tset outdir $path\n> -\t\t\treturn 1\n> -\t\t}\n> +\tif {[catch { \n> +\t\tset outdir [git rev-parse --resolve-git-dir $path] \n> +\t\t} ]} {\n> +\t\t\treturn 0\n\nI fixed trailing whitespace in a couple lines and a small style nitpick. You \ncan check them here [0]. Will merge. Thanks both.\n\n[0] https://github.com/prati0100/git-gui/commit/79089e52643ce1ba7d8494f32b2fb1891c926079\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"400283","messageId":"20200622145835.refvvs36h4a6a275@yadavpratyush.com","threadId":"53550","inReplyTo":"20200608093118.ppwpydlkd5bmsjh5@yadavpratyush.com","subject":"Re: [PATCH v2] git-gui: allow opening work trees from the startup dialog","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-06-22T14:58:35Z","receivedAt":"2020-06-22T14:58:44Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"On 08/06/20 03:01PM, Pratyush Yadav wrote:\n> +Cc Eric.\n> \n> On 06/06/20 04:33AM, Mikhail Terekhov via GitGitGadget wrote:\n> > From: Mikhail Terekhov <termim@gmail.com>\n> > \n> > In proc _is_git check that supplied path is a valid work tree path.\n> > This allows the choose_repository::pick dialog to accept path to a\n> > work tree directory.\n> > \n> > Signed-off-by: Mikhail Terekhov <termim@gmail.com>\n> > ---\n> >  lib/choose_repository.tcl | 29 +++++------------------------\n> >  1 file changed, 5 insertions(+), 24 deletions(-)\n> > \n> > diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl\n> > index e54f3e66d8f..07f29b0b13b 100644\n> > --- a/lib/choose_repository.tcl\n> > +++ b/lib/choose_repository.tcl\n> > @@ -357,31 +357,12 @@ proc _is_git {path {outdir_var \"\"}} {\n> >  \tif {$outdir_var ne \"\"} {\n> >  \t\tupvar 1 $outdir_var outdir\n> >  \t}\n> > -\tif {[file isfile $path]} {\n> > -\t\tset fp [open $path r]\n> > -\t\tgets $fp line\n> > -\t\tclose $fp\n> > -\t\tif {[regexp \"^gitdir: (.+)$\" $line line link_target]} {\n> > -\t\t\tset path [file join [file dirname $path] $link_target]\n> > -\t\t\tset path [file normalize $path]\n> > -\t\t}\n> > -\t}\n> > -\n> > -\tif {[file exists [file join $path HEAD]]\n> > -\t && [file exists [file join $path objects]]\n> > -\t && [file exists [file join $path config]]} {\n> > -\t\tset outdir $path\n> > -\t\treturn 1\n> > -\t}\n> > -\tif {[is_Cygwin]} {\n> > -\t\tif {[file exists [file join $path HEAD]]\n> > -\t\t && [file exists [file join $path objects.lnk]]\n> > -\t\t && [file exists [file join $path config.lnk]]} {\n> > -\t\t\tset outdir $path\n> > -\t\t\treturn 1\n> > -\t\t}\n> > +\tif {[catch { \n> > +\t\tset outdir [git rev-parse --resolve-git-dir $path] \n> > +\t\t} ]} {\n> > +\t\t\treturn 0\n> \n> I fixed trailing whitespace in a couple lines and a small style nitpick. You \n> can check them here [0]. Will merge. Thanks both.\n> \n> [0] https://github.com/prati0100/git-gui/commit/79089e52643ce1ba7d8494f32b2fb1891c926079\n\nMerged to git-gui/master.\n\n-- \nRegards,\nPratyush Yadav\n"}]}