0

I'm trying to push code using git to my remote server, but I get the error:

fatal: protocol error: bad line length character:
  8

I researched this bug and it turns out my .bashrc file that echos out a welcome screen is causing this error. What I would like to do is determine if this is a git push and to NOT display the welcome screen, or only display the screen when logging into SSH with no directory parameter:

ssh user@ssh-server.foo:/deployment/bare-git-repo

Here is the relevant lines in .bashrc:

if [ -e ./.doc ]
then
    cat ./.doc
    pm2 list
fi

Thanks in advance!

2

I don’t think there’s anything specific to git push hooks on the server, that you could use, but you could check whether you’re outputting to a terminal:

if [ -t 1 ] && [ -e ./.doc ]; then
    cat ./.doc
    pm2 list
fi

This will deal with a number of other cases where outputting the contents ./.doc doesn’t serve much purpose and could cause problems.

1

I suspect what you really want to do, is prevent running things which have no business being run in a non-interactive shell from running.

A common tactic for this, is to check whether stdin is not attached to a terminal via [[ ! -t 1 ]], or to check whether the bash process is not marked as interactive via [[ $- != *i* ]]. If one of these failure cases evaluates to true, then nothing else in your bashrc should get executed at all, and you should just return early.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.