[PATCH v2 02/11] git-gui: return status from choose_repository::pick
- From
Mark Levedahl <mlevedahl@gmail.com>
- Date
- May 20, 2026, 20:24 UTC
- Message-ID
- <20260520202411.108764-3-mlevedahl@gmail.com>
- In-Reply-To
- <20260520202411.108764-1-mlevedahl@gmail.com>
The repository picker (choose_repository::pick) on success always returns with the current directory at the root of the selected worktree, and with the global variable _gitdir holding the name of the git repository, possibly as a relative path. On failure, _gitdir = {}. If the selection was from the "recent" list, no validation has occurred.
There are too many side effects in this interface. Note that the picker only supports worktrees with a .git entry in the worktree root, so git repository and worktree discovery will work starting in the current directory on return. So, let's change pick to return a 0/1 value, 1 meaning a worktreee + repo was selected and the current directory is the worktree root, and leave validation and setting of _gitdir, _gitworktree, and _prefix to the caller. Note: pick actually does not return if something was not selected, rather it terminates git-gui. But, let's pretend at the call site that pick returns 0/false instead.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com> --- git-gui.sh | 10 ++++++++-- lib/choose_repository.tcl | 21 ++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh index 4ba25da7b6..4a736190a9 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1151,10 +1151,16 @@ if {[catch { } err]} { load_config 1 apply_config - choose_repository::pick - if {![file isdirectory $_gitdir]} { + if {![choose_repository::pick]} { exit 1 } + if {[catch { + set _gitdir [git rev-parse --git-dir] + } err]} { + catch {wm withdraw .} + error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] "\n\n$err"] + } + set _prefix {} set picked 1 } diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl index 7e1462a20c..4b06afee93 100644 --- a/lib/choose_repository.tcl +++ b/lib/choose_repository.tcl @@ -15,7 +15,7 @@ field w_recentlist ; # Listbox containing recent repositories field w_localpath ; # Entry widget bound to local_path field done 0 ; # Finished picking the repository? -field clone_ok false ; # clone succeeeded +field pick_ok 0 ; # true if repo pick/clone succeeded field local_path {} ; # Where this repository is locally field origin_url {} ; # Where we are cloning from field origin_name origin ; # What we shall call 'origin' @@ -220,6 +220,8 @@ constructor pick {} { if {$top eq {.}} { eval destroy [winfo children $top] } + + return $pick_ok } method _center {} { @@ -327,8 +329,7 @@ method _git_init {} { } _append_recentrepos [pwd] - set ::_gitdir .git - set ::_prefix {} + set pick_ok 1 return 1 } @@ -409,6 +410,7 @@ method _do_new2 {} { if {![_git_init $this]} { return } + set pick_ok 1 set done 1 } @@ -621,7 +623,7 @@ method _do_clone2 {} { } tkwait variable @done - if {!$clone_ok} { + if {!$pick_ok} { error_popup [mc "Clone failed."] return } @@ -632,18 +634,12 @@ method _do_clone2_done {ok} { if {$ok} { if {[catch { cd $local_path - set ::_gitdir .git - set ::_prefix {} _append_recentrepos [pwd] } err]} { set ok 0 } } - if {!$ok} { - set ::_gitdir {} - set ::_prefix {} - } - set clone_ok $ok + set pick_ok $ok set done 1 } @@ -721,8 +717,7 @@ method _do_open2 {} { } _append_recentrepos [pwd] - set ::_gitdir $actualgit - set ::_prefix {} + set pick_ok 1 set done 1 }
-- 2.54.0.99.14