mp-commit 535 Bytes
Newer Older
Michael Shigorin's avatar
Michael Shigorin committed
1 2 3 4 5
#!/bin/sh
# commit the directory ($1) with a message ($2) to git

. shell-error

6 7 8 9 10 11
INIT=
if [ "$1" = "-i" ]; then
	INIT=yes
	shift
fi

Michael Shigorin's avatar
Michael Shigorin committed
12 13 14 15 16 17
[ -d "$1" ] || fatal "$1 is not an existing directory"

if type -t git >&/dev/null && pushd "$1" >/dev/null; then
	if [ -z "$(git config --global user.name)" ]; then
		exit 0
	fi
18
	if [ -n "$INIT" -a ! -d .git ]; then
Michael Shigorin's avatar
Michael Shigorin committed
19 20 21 22
		git init -q || fatal "git init failed"
	fi
	if [ -n "$(git status -s)" ]; then
		git add . \
23
		&& git commit -anq -m "$2" \
Michael Shigorin's avatar
Michael Shigorin committed
24 25 26 27
		|| fatal "git add/commit failed"
	fi
	popd >/dev/null
fi