1

I have a symlink that points to some program: git-receive-pack -> git. I want to replace symlink with bash script and then call git as if it was called from symlink before replacement. I tried to call it as git $* but it sees first argument as git and not as git-receive-pack. How to invoke it correctly?

1 Answer 1

3

I would leave the git-receive-pack symlink alone, instead create a bash function (in ~/.bashrc). Something like this should do the trick:

function git-receive-pack() {
   ... (do your stuff)
   command git-receive-pack $*
}
Sign up to request clarification or add additional context in comments.

3 Comments

You could use command git-receive-pack to keep your PATH working instead of hardcoding /usr/bin, too.
Will that work for non-interactive shells? Like git push [email protected]:repo.git
Check for BASH_ENV environment variable, which is used for non-interactive shells. It should be set already. If it's unset, export it from .bash_profile as export BASH_ENV=~/.bashrc. The function will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.