Custom commands with git-shell

How to create custom commands for git-shell? According to the documentation :

When -c is specified, the program executes non-interactively; can be one of the git receive-pack, git upload-pack, gitupload-archive packages, a cvs server, or a command in COMMAND_DIR. The shell runs interactively if no arguments are given; in this case, COMMAND_DIR must exist, and any of the executable files in it can be called.

However, I'm not sure I understand this correctly. I created a user called gituser and gave him / usr / bin / git -shell as a shell. I created a directory called git -shell-commands and put a script called 'testy' in it, but I can't get it to work through git -shell.

Here is what I am trying to do from another machine:

$ ssh gituser@server.com testy
fatal: unrecognized command 'testy'

Note that git -shell works and responds, it just cannot find my user command.

And here is the script:

:/home/gituser/git-shell-commands# ls -l -a
total 12
drwxr-xr-x 2 gituser gituser 4096 Jan 22 17:35 .
drwxr-xr-x 4 gituser gituser 4096 Jan 22 13:57 ..
-rwxr-xr-x 1 gituser gituser   26 Jan 22 13:58 testy
:/home/gituser/git-shell-commands# ./testy
hello!
:/home/sodigit/git-shell-commands# cat testy
echo "hello!"

What am I doing wrong? How to run custom commands using git-shell?

+5
source share
2 answers

As it turned out, this feature was introduced in git 1.7.4. I am using debian squeeze which contains an older version of git, so this is exactly what did not work.

If you are having this problem, check out the git version.

However, with git 1.7.10, user commands only work interactively, not with -c. I have not tried the latest git, although perhaps this problem is not related to the software version.

+5
source

pre-1.7.4 ( 1.7.10), script git -shell:

#!/bin/bash                                                                     

cmdline=($1)
cmd=$(basename "${cmdline[0]}")

if [ -z "$cmd" ] ; then
    exec git-shell
elif [ -n "$cmd" -a -x ~/git-shell-commands/"$cmd" ] ; then
    ~/git-shell-commands/"$cmd" "${cmdline[@]:1}"
else
    exec git-shell -c "$1"
fi

"git -shell", script, "-c" script.

git -shell, script . :

#!/bin/bash                                                                     

cmd=$(basename $1)

if [ -z "$cmd" ] ; then
    exec git-shell
elif [ -n "$cmd" -a -x ~/git-shell-commands/"$cmd" ] ; then
    shift
    ~/git-shell-commands/"$cmd" "$@"
else
    exec git-shell -c "$*"
fi

, authorize_keys :

command="sshsh $SSH_ORIGINAL_COMMAND" ...

, script pre-1.7.4 ( ": , ?"? git - shell), 1.7.4 .

: . . , ~/ git -shell- ( git -shell 1.7.4 , - ).

+1