12

When I add a new tool to git-gui, the dialog indicates that I could use some variables to be passed to the tool ($REVISION, $ARGS, $FILENAME).

Are there any other parameters that are not documented (for example the current repo directory, etc.)? Why are they not contained in the documentation of the git-gui?

My current use case is that I have two scripts that enable/disable a pre-commit hook. Currently, I have to open my Windows Explorer and double-click the batch-files which is a bit clumsy. Easier way would be to do that directly out of git-gui...

As an alternative (side-question), I would also be interested in bypassing the pre-commit hook (i.e. pass --no-verify when committing) out of git-gui.

eckes
  • 64,417
  • 29
  • 168
  • 201

3 Answers3

5

When looking at the git-gui sources, I find (not present in git-gui man page):

  • git-gui.sh:
    • $GITGUI_VERBOSE, to enable verbose loading
    • SSH_ASKPASS, to suggest our implementation of askpass, if none is set
    • GIT_DIR and GIT_WORK_TREE, for repository setup
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I see `set s "usage: $::argv0 $::subcommand $::subcommand_args"`: maybe there is a way to pass and execute a sub git command... – VonC Mar 23 '12 at 12:38
  • @eckes right, those are the variable taken into account by git-gui at launch time. However, `GIT_DIR` and `GIT_WORK_TREE` should still be set (`Tools --> Add`) and taken into account by the sub-command. I got nothing on the `--no-verify` though. – VonC Mar 23 '12 at 13:12
3

I personal extended git-gui for having tools working on multiple files

In the tools.tcl file, add the following 2 lines

set env(GIT_GUITOOL) $fullname
set env(FILENAME) $current_diff_path
>> set env(FILENAMES) [array names selected_paths]

and :

unset env(GIT_GUITOOL)
unset env(FILENAME)
>> unset env(FILENAMES)

Use $FILENAMES instead of $FILENAME in your tool, and list of files will be passed on separated by spaces (very useful for creating a tool like : rm $FILENAMES )

Note on $FILENAME (and $FILENAMES) Git gui tool mechanism doesn't work with files containing spaces I tried quoting each file, by writing

set env(FILENAMES) [string map { \{ \" \} \" } [array names selected_paths]]

But Console::exec seems to separate args on space and escape each argument.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Two notes to the previous solution:

  1. global selected_paths

to post non empty $FILENAMES to the command it is neccessary to declare selected_paths as global

  1. files containing spaces

to post files containing spaces use "${FILENAMES[@]}" instead of plain $FILENAMES.

You can see how the pathes are sent to a command by using command printf '\"%s\" ' e.g.

printf '\"%s\" ' FILENAMES= "${FILENAMES[@]}"

kazo
  • 11
  • 2