It is well documented that I can add a new command to git by placing the script/program git-foobar on my $PATH, which I can then invoke as git foobar.
But what if I want to extend an existing git command? For example, the git worktree command has verbs add,list,lock,etc.. I have a very specific way in which I organize where I keep and how I name worktrees. I have written a script `git-worktree' that has a "main" function that looks like this:
declare action=$1
shift;
if [[ "$action" =~ -h ]]
then
script-usage
return 0
fi
case $action in
create | delete )
if [[ "$1" =~ -h ]]
then
script-usage
return 0
else
"git-worktree-${action}" "$@"
return $?
fi
;;
*)
"${git_bin}/git-worktree" "$@"
return $?
;;
esac
If I type 'create' or 'delete' I call functions defined elsewhere in my script. For anything else, I just pass along to the real git worktree command.
Except that it doesn't quite work. Typing git-worktree executes my script. Typing git worktree does NOT run my script.
Is there something I am missing or can I not extend existing git commands in the same way in which I can add new commands?