From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
A re-issue of the patchest to make git-gui more robust towards
non-standard repository setup, with two additional fixes.
The first three patches are unchanged from the previous iteration (still
waiting for review, actually).
The 4th sets GIT_DIR and GIT_WORK_TREE in git-gui to ensure that all
external tool invocation work in the same setup.
The last one also updates the shortcut library to make use of
_gitworktree instead of the old assumption that the worktree is the
updir of the git dir. I can't really test this patch though because
I don't have Windows.
Giuseppe Bilotta (5):
git-gui: handle non-standard worktree locations
git-gui: handle bare repos correctly
git-gui: work from the .git dir
git-gui: set GIT_DIR and GIT_WORK_TREE after setup
git-gui: update shortcut tools to use _gitworktree
git-gui/git-gui.sh | 101 ++++++++++++++++++++++++++++++++++------------
git-gui/lib/shortcut.tcl | 7 ++-
2 files changed, 79 insertions(+), 29 deletions(-)
From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
Don't rely on the git worktree being the updir of the gitdir, since it
might not be. Instead, define (and use) a new _gitworktree global
variable, setting it to $GIT_WORK_TREE if present, falling back to
core.worktree if defined, and finally to whatever we guess the correct
worktree is. Getting core.worktree requires the config from the alleged
git dir _gitdir to be loaded early.
Supporting non-standard worktree locations also breaks the git-gui
assumption (made when calling gitk) that the worktree was the dirname of
$_gitdir and that, by consequence, the git dir could be set to the tail
of $_gitdir once we changed to the worktree root directory. Therefore,
we need to export a GIT_DIR environment variable set to the full,
normalized path of $_gitdir instead. We also skip changing to the worktree
directory if it's empty (i.e. if we're working on a bare repository).
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui/git-gui.sh | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
@@ -1090,13 +1091,25 @@ if {![file isdirectory $_gitdir]} {error_popup[strcat[mc"Git directory not found:"]"\n\n$_gitdir"]exit1}+# _gitdir exists, so try loading the config+load_config0+apply_config+# try to set work tree from environment, falling back to core.worktree+if{[catch{set_gitworktree$env(GIT_WORK_TREE)}]}{+set_gitworktree[get_configcore.worktree]+}if{$_prefixne{}}{-regsub-all{[^/]+/}$_prefix../cdup+if{$_gitworktreeeq{}}{+regsub-all{[^/]+/}$_prefix../cdup+}else{+setcdup$_gitworktree+}if{[catch{cd$cdup}err]}{catch{wmwithdraw.}error_popup[strcat[mc"Cannot move to top of working directory:"]"\n\n$err"]exit1}+set_gitworktree[pwd]unsetcdup}elseif{![is_enabledbare]}{if{[lindex[filesplit$_gitdir]end]ne{.git}}{
@@ -1104,11 +1117,15 @@ if {$_prefix ne {}} {error_popup[strcat[mc"Cannot use funny .git directory:"]"\n\n$_gitdir"]exit1}-if{[catch{cd[filedirname$_gitdir]}err]}{+if{$_gitworktreeeq{}}{+set_gitworktree[filedirname$_gitdir]+}+if{[catch{cd$_gitworktree}err]}{catch{wmwithdraw.}-error_popup[strcat[mc"No working directory"]" [file dirname $_gitdir]:\n\n$err"]+error_popup[strcat[mc"No working directory"]" $_gitworktree:\n\n$err"]exit1}+set_gitworktree[pwd]}set_reponame[filesplit[filenormalize$_gitdir]]if{[lindex$_reponameend]eq{.git}}{
@@ -1921,6 +1938,7 @@ proc incr_font_size {font {amt 1}} {setstarting_gitk_msg[mc"Starting gitk... please wait..."] procdo_gitk{revs}{+global_gitworktree# -- Always start gitk through whatever we were loaded with. This# lets us bypass using shell process on Windows systems.#
@@ -1967,7 +1988,7 @@ proc do_explore {} {# freedesktop.org-conforming system is our best shotsetexplorer"xdg-open"}-evalexec$explorer[list[filenativename[filedirname[gitdir]]]]&+evalexec$explorer$_gitworktree&}setis_quitting0
@@ -2331,8 +2352,6 @@ proc show_less_context {} {#### ui construction-load_config0-apply_configsetui_comm{}# -- Menu Bar
@@ -3370,7 +3389,7 @@ unset isetfile_lists($ui_index)[list]setfile_lists($ui_workdir)[list]-wmtitle."[appname] ([reponame]) [file normalize [file dirname [gitdir]]]"+wmtitle."[appname] ([reponame]) [file normalize $_gitworktree]" focus-force$ui_comm# -- Warn the user about environmental problems. Cygwin's Tcl
From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
Rather than juggling $GIT_DIR around the invocation of gitk, set it
(and $GIT_WORK_TREE) after finishing setup, ensuring that any external
tool works with the setup we're running with.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui/git-gui.sh | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)
From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
When git-gui is run from a .git dir, _gitdir would be set to "." by
rev-parse, something that confuses the worktree detection.
Fix by expanding the value of _gitdir to pwd in this special case.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui/git-gui.sh | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
@@ -1102,6 +1102,8 @@ if {[catch {set_prefix{}}]&&[catch{+# beware that from the .git dir this sets _gitdir to .+# and _prefix to the empty stringset_gitdir[gitrev-parse--git-dir]set_prefix[gitrev-parse--show-prefix]}err]}{
@@ -1110,6 +1112,14 @@ if {[catch {choose_repository::picksetpicked1}++# we expand the _gitdir when it's just a single dot (i.e. when we're being+# run from the .git dir itself) lest the routines to find the worktree+# get confused+if{$_gitdireq"."}{+set_gitdir[pwd]+}+if{![fileisdirectory$_gitdir]&&[is_Cygwin]}{catch{set_gitdir[execcygpath--windows$_gitdir]}}
From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
Refactor checking for a bare repository into its own proc, that relies
on git rev-parse --is-bare-repository if possible. For older versions of
git we fall back to a logic such that the repository is considered bare
if:
* either the core.bare setting is true
* or the worktree is not set and the directory name ends with .git
The error message for the case of an unhandled bare repository is also
updated to reflect the fact that the problem is not the funny name but
the bareness.
The new refactored proc is also used to disable the menu entry to
explore the working copy, and to skip changing to the worktree before
the gitk invocation.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui/git-gui.sh | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
@@ -1112,9 +1139,9 @@ if {$_prefix ne {}} {set_gitworktree[pwd]unsetcdup}elseif{![is_enabledbare]}{-if{[lindex[filesplit$_gitdir]end]ne{.git}}{+if{[is_bare]}{catch{wmwithdraw.}-error_popup[strcat[mc"Cannot use funny .git directory:"]"\n\n$_gitdir"]+error_popup[strcat[mc"Cannot use bare repository:"]"\n\n$_gitdir"]exit1}if{$_gitworktreeeq{}}{
@@ -2383,10 +2410,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {# menu.mbar.repository-.mbar.repositoryaddcommand\--label[mc"Explore Working Copy"]\--command{do_explore}-.mbar.repositoryaddseparator+if{![is_bare]}{+.mbar.repositoryaddcommand\+-label[mc"Explore Working Copy"]\+-command{do_explore}+.mbar.repositoryaddseparator+} .mbar.repositoryaddcommand\-label[mc"Browse Current Branch's Files"]\
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:48:05
Giuseppe Bilotta [off-list ref] wrote:
Rather than juggling $GIT_DIR around the invocation of gitk, set it
(and $GIT_WORK_TREE) after finishing setup, ensuring that any external
tool works with the setup we're running with.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui/git-gui.sh | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)
This patch has merge conflicts with changes from Jens Lehmann
related to starting gitk inside of a submodule. Since I merged
his menu code first, I would appreciate it if you could rebase this
one patch on top of my latest master:
git://git.spearce.org/git-gui.git master
The other 4 patches in this series are already applied, thanks.
--
Shawn.
From: Giuseppe Bilotta <hidden> Date: 2016-06-15 22:48:05
Rather than juggling with the env var GIT_DIR around the invocation of
gitk, set it and GIT_WORK_TREE after finishing setup, ensuring that any
external tool works with the setup we're running with.
This also allows us to remove a couple of conditionals when running gitk
or git gui in a submodule, as we know that the variables are present and
have to be unset and reset before and after the invocation.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui.sh | 43 ++++++++++++++++++++-----------------------
1 files changed, 20 insertions(+), 23 deletions(-)
@@ -1171,6 +1171,9 @@ if {[lindex $_reponame end] eq {.git}} {set_reponame[lindex$_reponameend]}+setenv(GIT_DIR)$_gitdir+setenv(GIT_WORK_TREE)$_gitworktree+########################################################################## global init
@@ -1979,7 +1982,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."] procdo_gitk{revs{is_submodulefalse}}{globalcurrent_diff_pathfile_statescurrent_diff_sideui_index-global_gitworktree+global_gitdir_gitworktree# -- Always start gitk through whatever we were loaded with. This# lets us bypass using shell process on Windows systems.
@@ -2024,15 +2020,18 @@ proc do_gitk {revs {is_submodule false}} {}setrevs$old_sha1...$new_sha1}-if{[infoexistsenv(GIT_DIR)]}{-unsetenv(GIT_DIR)-}+# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones+# we've been using for the main repository, so unset them.+# TODO we could make life easier (start up faster?) for gitk+# by setting these to the appropriate values to allow gitk+# to skip the heuristics to find their proper value+unsetenv(GIT_DIR)+unsetenv(GIT_WORK_TREE)}evalexec$cmd$revs"--""--"&-if{$old_GIT_DIRne{}}{-setenv(GIT_DIR)$old_GIT_DIR-}+setenv(GIT_DIR)$_gitdir+setenv(GIT_WORK_TREE)$_gitworktreecd$pwdui_status$::starting_gitk_msg
@@ -2053,22 +2052,20 @@ proc do_git_gui {} {error_popup[mc"Couldn't find git gui in PATH"]}else{globalenv+global_gitdir_gitworktree-if{[infoexistsenv(GIT_DIR)]}{-setold_GIT_DIR$env(GIT_DIR)-unsetenv(GIT_DIR)-}else{-setold_GIT_DIR{}-}+# see note in do_gitk about unsetting these vars when+# running tools in a submodule+unsetenv(GIT_DIR)+unsetenv(GIT_WORK_TREE)setpwd[pwd]cd$current_diff_pathevalexec$exegui&-if{$old_GIT_DIRne{}}{-setenv(GIT_DIR)$old_GIT_DIR-}+setenv(GIT_DIR)$_gitdir+setenv(GIT_WORK_TREE)$_gitworktreecd$pwdui_status$::starting_gitk_msg
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:48:05
Giuseppe Bilotta [off-list ref] wrote:
Rather than juggling with the env var GIT_DIR around the invocation of
gitk, set it and GIT_WORK_TREE after finishing setup, ensuring that any
external tool works with the setup we're running with.
This also allows us to remove a couple of conditionals when running gitk
or git gui in a submodule, as we know that the variables are present and
have to be unset and reset before and after the invocation.
Signed-off-by: Giuseppe Bilotta <redacted>
---
git-gui.sh | 43 ++++++++++++++++++++-----------------------
1 files changed, 20 insertions(+), 23 deletions(-)