Last active
December 26, 2016 09:08
-
-
Save chiastolite/781654396ade961ced79894cfefa4a53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Gitリポジトリ内ではなければ処理をしない | |
git status > /dev/null 2>&1 | |
if [ $? != 0 ] ; then | |
echo "Not a git repository" | |
exit 1 | |
fi | |
# stagingされているファイルがある場合は処理をしない | |
if [ -n "`git diff --name-only --cached`" ]; then | |
echo 'Some file(s) are staged.' | |
exit 1 | |
fi | |
# 元々あったファイルを記録 | |
current_files="$(git ls-files --others --exclude-standard)" | |
# コマンドを実行 | |
CMD=$@ | |
if ! $@; then | |
echo "Failed: ${CMD}" | |
exit 1 | |
fi | |
# コマンド実行結果により追加されたファイルを記録 | |
new_files=`diff <(echo "${current_files}") <((git ls-files --others --exclude-standard)) | grep -e '^> ' | sed "s/^> //"` | |
if [ -z "$new_files" ]; then | |
echo "No change" | |
exit 1 | |
fi | |
# 新しいファイルを記録してコミットを作成 | |
git add ${new_files} | |
git commit -m "[rec] ${CMD}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment