manu
manu

Reputation: 3843

Sourced git alias fails

I have setup a custom git alias to make a pretty git log like this in my ~/.gitconfig

[alias]
   l = "!source ~/.githelpers && git_pretty_log"

My ~/.githelpers file contains the following:

#!/bin/bash

HASH="%C(yellow)%h%C(reset)"
RELATIVE_TIME="%C(green)%ar%C(reset)"
AUTHOR="%C(bold blue)%an%C(reset)"
REFS="%C(red)%d%C(reset)"
SUBJECT="%s"

FORMAT="$HASH{$RELATIVE_TIME{$AUTHOR{$REFS $SUBJECT"

function git_pretty_log() {
    git log --graph --pretty="tformat:$FORMAT" $* |
    column -t -s '{' |
    less -FXRS
}

But when I do git l in any repo I have I get:

$ git l
source ~/.githelpers && git_pretty_log: 1: source ~/.githelpers && git_pretty_log: source: not found
fatal: While expanding alias 'l': 'source ~/.githelpers && git_pretty_log': Aucun fichier ou dossier de ce type

Any ideas?

Upvotes: 1

Views: 151

Answers (2)

Sir Athos
Sir Athos

Reputation: 9867

The error seems to be that source is not an external binary, but instead a bash builtin.

$ git config alias.foo '!source .gitfoo'
$ git foo
source .gitfoo: 1: source .gitfoo: source: not found

Wrapping all this with a bash -c solves the problem.

$ git config alias.foo '!'"bash -c 'source .gitfoo && gitfoobar'"
$ echo 'function gitfoobar() { echo foo bar; }' >.gitfoo
$ git foo
foo bar

For your case:

git config --global alias.l '!'"bash -c 'source ~/.githelpers && git_pretty_log'"

Upvotes: 3

Bob Gilmore
Bob Gilmore

Reputation: 13758

Remove the quotation marks; it should just be:

[alias]
    l = !source ~/.githelpers && git_pretty_log

Otherwise, you're trying to run one long command that doesn't exist, just as the error message told you.

Upvotes: -1

Related Questions