2rs2ts
2rs2ts

Reputation: 11066

Make git push a no-op

I have a handy sbt plugin which does a bunch of software release and lifecycle management stuff, and one of the things it does is automatically push the commits it makes to the configured upstream branch.

Unfortunately, that upstream is temporarily down. I can just push the commits later, so for now, I'd like my sbt plugin to just no-op when it does a git push. How can I achieve this?

Upvotes: 1

Views: 2140

Answers (2)

jthill
jthill

Reputation: 60585

Change the push url for the remote to "."

git config remote.origin.pushurl .

then when the real one's back, undo the redirect:

git config --unset remote.origin.pushurl

If your branches are tracking differently-named upstream branches this will cause problems, in that case just make a nonce repo:

git clone --template '' -s --bare . ../nonce
git config remote.origin.pushurl ../nonce

which will isolate the namespaces. You can just delete the nonce repo when you're done with it.

Upvotes: 2

tripleee
tripleee

Reputation: 189936

You can create a simple wrapper for the git command which rejects any push. Here is a fairly trivial Bash function.

git () {
    case $1 in
      push)
        echo "git: push disabled" >&2
        return 1 ;;
    esac
    command git "$@"
}

This is crude -- it does no option parsing, so e.g. git --verbose push bypasses the case check. But for your stated problem, it probably doesn't need to be any more sophisticated.

Upvotes: 0

Related Questions