# Git GUI vs interactive post-commit hooks

9 messages from 2008-05-19 to 2008-05-22. Participants: Alexander Gladysh, Björn Steinbrink, Alex Riesen, Jeff King.
Thread: https://gitlist.dev/t/13572

## Alexander Gladysh, 2008-05-19 10:48

Subject: Git GUI vs interactive post-commit hooks
Message-ID: <c6c947f60805190348g3395f8degae81963b402856b6@mail.gmail.com>
URL: https://gitlist.dev/e/c6c947f60805190348g3395f8degae81963b402856b6%40mail.gmail.com

```
Hi, list!

$ git --version
git version 1.5.5.1

I have a post-commit hook which does backups for me:

  username=agladysh
  for name in `git branch | cut -b3-`
  do
    remote=$username-$name
    echo pushing $name as $remote
    git push backup +$name:refs/heads/$remote
  done

The backup repo is behind ssh. Recently I have put password on my ssh
key and post-commit hook ask me for password once for each branch.
This makes unhappy commit process from Git GUI -- after I shut it
down, there are multiple ssh key password prompts in the shell from
where I launched it, and it does not display any input I enter.

Any advice? I do want to input password for my key each time I use it.

Thanks in advance,
Alexander.

```

## Björn Steinbrink, 2008-05-19 13:19

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080519131942.GA5526@atjola.homenet>
URL: https://gitlist.dev/e/20080519131942.GA5526%40atjola.homenet
In-Reply-To: <c6c947f60805190348g3395f8degae81963b402856b6@mail.gmail.com>

```
On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> Hi, list!
> 
> $ git --version
> git version 1.5.5.1
> 
> I have a post-commit hook which does backups for me:
> 
>   username=agladysh
>   for name in `git branch | cut -b3-`
>   do
>     remote=$username-$name
>     echo pushing $name as $remote
>     git push backup +$name:refs/heads/$remote
>   done

Isn't that what "git push --all" does? And that will only ask for a
password once, not for every branch.

> The backup repo is behind ssh. Recently I have put password on my ssh
> key and post-commit hook ask me for password once for each branch.
> This makes unhappy commit process from Git GUI -- after I shut it
> down, there are multiple ssh key password prompts in the shell from
> where I launched it, and it does not display any input I enter.
> 
> Any advice? I do want to input password for my key each time I use it.

For a graphical tool, you might want to use something like
gtk-led-askpass, which shows a window with a password prompt. SSH will
make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
from a terminal. Unfortunately, the latter is probably not true for git
gui most of the time.

One way hack around this is to do "setsid git push ..." in your
post-commit hook. But that will break if you have no X or no tool for
SSH_ASKPASS.

Another really hackish work-around is to
replace:
 exec 'wish' "$argv0" -- "$@"
with
 exec 'setsid' 'wish' "$argv0" -- "$@"

in git-gui. Git gui will then get its own session, detached from the
terminal and ssh will start using SSH_ASKPASS. That at least won't break
when you're not running X (simply because you won't be running git gui
then ;-)), but doesn't feel smart either.

Maybe someone else can come up with a sane solution that makes git gui
more SSH_ASKPASS-friendly.

Björn

```

## Alexander Gladysh, 2008-05-19 13:42

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <c6c947f60805190642x7d44ef04h4090cbb687de69e@mail.gmail.com>
URL: https://gitlist.dev/e/c6c947f60805190642x7d44ef04h4090cbb687de69e%40mail.gmail.com
In-Reply-To: <20080519131942.GA5526@atjola.homenet>

```
On Mon, May 19, 2008 at 5:19 PM, Björn Steinbrink <B.Steinbrink@gmx.de> wrote:
> On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
>> Hi, list!
>>
>> $ git --version
>> git version 1.5.5.1
>>
>> I have a post-commit hook which does backups for me:
>>
>>   username=agladysh
>>   for name in `git branch | cut -b3-`
>>   do
>>     remote=$username-$name
>>     echo pushing $name as $remote
>>     git push backup +$name:refs/heads/$remote
>>   done
>
> Isn't that what "git push --all" does? And that will only ask for a
> password once, not for every branch.

git push --all would not rename my branches... But, I guess, this can
be done as preparation step somehow.

>> The backup repo is behind ssh. Recently I have put password on my ssh
>> key and post-commit hook ask me for password once for each branch.
>> This makes unhappy commit process from Git GUI -- after I shut it
>> down, there are multiple ssh key password prompts in the shell from
>> where I launched it, and it does not display any input I enter.
>>
>> Any advice? I do want to input password for my key each time I use it.
>
> For a graphical tool, you might want to use something like
> gtk-led-askpass, which shows a window with a password prompt. SSH will
> make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> from a terminal. Unfortunately, the latter is probably not true for git
> gui most of the time.

<Useful advice regarding how to solve SSH_ASKPASS issue skipped.>

Thanks, I would try that. I'm mostly working from X, so lack of X
should be not an issue... However I'd like to avoid patching my local
copy of git as much as possible. :-)

> Maybe someone else can come up with a sane solution that makes git gui
> more SSH_ASKPASS-friendly.

That would be great.

Thank you,
Alexander.

```

## Björn Steinbrink, 2008-05-19 14:11

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080519141112.GA12304@atjola.homenet>
URL: https://gitlist.dev/e/20080519141112.GA12304%40atjola.homenet
In-Reply-To: <c6c947f60805190642x7d44ef04h4090cbb687de69e@mail.gmail.com>

```
On 2008.05.19 17:42:05 +0400, Alexander Gladysh wrote:
> On Mon, May 19, 2008 at 5:19 PM, Björn Steinbrink <B.Steinbrink@gmx.de> wrote:
> > On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> >> Hi, list!
> >>
> >> $ git --version
> >> git version 1.5.5.1
> >>
> >> I have a post-commit hook which does backups for me:
> >>
> >>   username=agladysh
> >>   for name in `git branch | cut -b3-`
> >>   do
> >>     remote=$username-$name
> >>     echo pushing $name as $remote
> >>     git push backup +$name:refs/heads/$remote
> >>   done
> >
> > Isn't that what "git push --all" does? And that will only ask for a
> > password once, not for every branch.
> 
> git push --all would not rename my branches... But, I guess, this can
> be done as preparation step somehow.

Oh, oops, didn't notice the $remote stuff, sorry.

> >> The backup repo is behind ssh. Recently I have put password on my ssh
> >> key and post-commit hook ask me for password once for each branch.
> >> This makes unhappy commit process from Git GUI -- after I shut it
> >> down, there are multiple ssh key password prompts in the shell from
> >> where I launched it, and it does not display any input I enter.
> >>
> >> Any advice? I do want to input password for my key each time I use it.
> >
> > For a graphical tool, you might want to use something like
> > gtk-led-askpass, which shows a window with a password prompt. SSH will
> > make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> > from a terminal. Unfortunately, the latter is probably not true for git
> > gui most of the time.
> 
> <Useful advice regarding how to solve SSH_ASKPASS issue skipped.>
> 
> Thanks, I would try that. I'm mostly working from X, so lack of X
> should be not an issue... However I'd like to avoid patching my local
> copy of git as much as possible. :-)

Well, the "lack of X" issue only arises if you patch your post-commit
hook. Adding setsid to the git push command was supposed to happen there
;-) You could probably even make that conditional, so that setsid is
only used then DISPLAY is set, then it should even work when there's no
X, but still be annoying when you commit from a terminal... (At least I
would prefer to enter the password in the terminal then).

Björn

```

## Alex Riesen, 2008-05-20 22:31

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080520223158.GB13123@steel.home>
URL: https://gitlist.dev/e/20080520223158.GB13123%40steel.home
In-Reply-To: <20080519131942.GA5526@atjola.homenet>

```
Bj?rn Steinbrink, Mon, May 19, 2008 15:19:42 +0200:
> On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> > 
> > Any advice? I do want to input password for my key each time I use it.
> 
> For a graphical tool, you might want to use something like
> gtk-led-askpass, which shows a window with a password prompt. SSH will
> make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> from a terminal. Unfortunately, the latter is probably not true for git
> gui most of the time.

Redirect stdin from /dev/null

```

## Björn Steinbrink, 2008-05-20 23:02

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080520230204.GA5383@atjola.homenet>
URL: https://gitlist.dev/e/20080520230204.GA5383%40atjola.homenet
In-Reply-To: <20080520223158.GB13123@steel.home>

```
On 2008.05.21 00:31:58 +0200, Alex Riesen wrote:
> Bj?rn Steinbrink, Mon, May 19, 2008 15:19:42 +0200:
> > On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> > > 
> > > Any advice? I do want to input password for my key each time I use it.
> > 
> > For a graphical tool, you might want to use something like
> > gtk-led-askpass, which shows a window with a password prompt. SSH will
> > make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> > from a terminal. Unfortunately, the latter is probably not true for git
> > gui most of the time.
> 
> Redirect stdin from /dev/null

Does that actually work for you? It didn't work for me, because ssh then
simply goes and opens /dev/tty to ask for the password.

$ ssh -V
OpenSSH_4.7p1 Debian-10, OpenSSL 0.9.8g 19 Oct 2007

Björn

```

## Jeff King, 2008-05-20 23:16

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080520231631.GB22934@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080520231631.GB22934%40sigill.intra.peff.net
In-Reply-To: <20080520230204.GA5383@atjola.homenet>

```
On Wed, May 21, 2008 at 01:02:04AM +0200, Björn Steinbrink wrote:

> > Redirect stdin from /dev/null
> 
> Does that actually work for you? It didn't work for me, because ssh then
> simply goes and opens /dev/tty to ask for the password.
> 
> $ ssh -V
> OpenSSH_4.7p1 Debian-10, OpenSSL 0.9.8g 19 Oct 2007

I had to perform this same task a few weeks ago, and ended up using
'setsid' to get rid of the controlling tty. You may also need to unset
SSH_ASKPASS and DISPLAY.

-Peff

```

## Alex Riesen, 2008-05-22 12:53

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080522125301.GD3206@steel.home>
URL: https://gitlist.dev/e/20080522125301.GD3206%40steel.home
In-Reply-To: <20080520230204.GA5383@atjola.homenet>

```
Björn Steinbrink, Wed, May 21, 2008 01:02:04 +0200:
> On 2008.05.21 00:31:58 +0200, Alex Riesen wrote:
> > Bj?rn Steinbrink, Mon, May 19, 2008 15:19:42 +0200:
> > > On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> > > > 
> > > > Any advice? I do want to input password for my key each time I use it.
> > > 
> > > For a graphical tool, you might want to use something like
> > > gtk-led-askpass, which shows a window with a password prompt. SSH will
> > > make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> > > from a terminal. Unfortunately, the latter is probably not true for git
> > > gui most of the time.
> > 
> > Redirect stdin from /dev/null
> 
> Does that actually work for you? It didn't work for me, because ssh then
> simply goes and opens /dev/tty to ask for the password.
> 
> $ ssh -V
> OpenSSH_4.7p1 Debian-10, OpenSSL 0.9.8g 19 Oct 2007
> 

No :( I took this information from sshs manpage:

     SSH_ASKPASS           If ssh needs a passphrase, it will read the
                           passphrase from the current terminal if it was run
                           from a terminal.  If ssh does not have a terminal
                           associated with it but DISPLAY and SSH_ASKPASS are
                           set, it will execute the program specified by
                           SSH_ASKPASS and open an X11 window to read the
                           passphrase.  This is particularly useful when call‐
                           ing ssh from a .xsession or related script.  (Note
                           that on some machines it may be necessary to redi‐
                           rect the input from /dev/null to make this work.)

```

## Björn Steinbrink, 2008-05-22 15:12

Subject: Re: Git GUI vs interactive post-commit hooks
Message-ID: <20080522151246.GA9765@atjola.homenet>
URL: https://gitlist.dev/e/20080522151246.GA9765%40atjola.homenet
In-Reply-To: <20080522125301.GD3206@steel.home>

```
On 2008.05.22 14:53:01 +0200, Alex Riesen wrote:
> Björn Steinbrink, Wed, May 21, 2008 01:02:04 +0200:
> > On 2008.05.21 00:31:58 +0200, Alex Riesen wrote:
> > > Bj?rn Steinbrink, Mon, May 19, 2008 15:19:42 +0200:
> > > > On 2008.05.19 14:48:14 +0400, Alexander Gladysh wrote:
> > > > > 
> > > > > Any advice? I do want to input password for my key each time I use it.
> > > > 
> > > > For a graphical tool, you might want to use something like
> > > > gtk-led-askpass, which shows a window with a password prompt. SSH will
> > > > make use of it if SSH_ASKPASS contains its path _and_ ssh is not started
> > > > from a terminal. Unfortunately, the latter is probably not true for git
> > > > gui most of the time.
> > > 
> > > Redirect stdin from /dev/null
> > 
> > Does that actually work for you? It didn't work for me, because ssh then
> > simply goes and opens /dev/tty to ask for the password.
> > 
> > $ ssh -V
> > OpenSSH_4.7p1 Debian-10, OpenSSL 0.9.8g 19 Oct 2007
> > 
> 
> No :( I took this information from sshs manpage:
> 
>      SSH_ASKPASS           If ssh needs a passphrase, it will read the
>                            passphrase from the current terminal if it was run
>                            from a terminal.  If ssh does not have a terminal
>                            associated with it but DISPLAY and SSH_ASKPASS are
>                            set, it will execute the program specified by
>                            SSH_ASKPASS and open an X11 window to read the
>                            passphrase.  This is particularly useful when call‐
>                            ing ssh from a .xsession or related script.  (Note
>                            that on some machines it may be necessary to redi‐
>                            rect the input from /dev/null to make this work.)

Yeah, that got me trying the redirection, too. But the "If ssh does not
have a terminal associated" part is actually what counts, it seems.
Because ssh falls back to /dev/tty if stdin doesn't work. Guess the
stdin redirect might just be required in some cases, where it would use
/dev/stdin directly, so you force it to try /dev/tty and then use
SSH_ASKPASS.

Björn

```
