Last active
January 9, 2017 01:00
-
-
Save artifactsauce/e3fd27c84abc208d39da2a90160268d0 to your computer and use it in GitHub Desktop.
ディレクトリを定期的に監視してGitリポジトリに間違ったEmailをコミットしない ref: http://qiita.com/artifactsauce/items/10141d6473bbb0e64cb1
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
$ git config user.email [email protected] |
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
$ watch-git-email.sh /PATH/TO/DIRECTORY/ROOT [email protected] & |
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
$ pkill -KILL -f watch-git-email.sh |
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
while true; do | |
sleep $INTERVAL | |
# something to do | |
done |
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
$ rm -rf .git | |
$ git init |
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
echo -e "[$(date +"%x %T")] \033[35m[ERROR] $*\033[m" >&2 |
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
#!/usr/bin/env bash | |
set -eu | |
: ${DEBUG_MODE:=0} | |
: ${INTERVAL:=1} #監視間隔, 秒で指定 | |
_.error() { | |
echo -e "[$(date +"%x %T")] \033[35m[ERROR] $*\033[m" >&2 | |
} | |
_.debug() { | |
[ "$DEBUG_MODE" -eq 0 ] && return 0 | |
echo -e "[$(date +"%x %T")] \033[34m[DEBUG] $*\033[m" >&2 | |
} | |
_.get_stamp() { | |
ls -l --full-time $1 | awk '{print $1 $6 $7 $8 $9}' | openssl sha | |
} | |
_.run() { | |
local target_directory=$1 | |
local expect_email=$2 | |
_.debug "Find in $target_directory" | |
while read; do | |
_.debug "Change directory: $REPLY" | |
cd $(dirname $REPLY) | |
local actual_email=$(git config user.email) | |
if [ "$expect_email" = "$actual_email" ]; then | |
continue | |
fi | |
_.debug "Change git user emal in: $REPLY" | |
git config user.email $expect_email | |
done <<EOS | |
$(find $target_directory -type d -name ".git") | |
EOS | |
} | |
_.watch() { | |
local target_directory=$1 | |
local last=$(_.get_stamp $target_directory) | |
while true; do | |
sleep $INTERVAL | |
local current=$(_.get_stamp $target_directory) | |
_.debug "Stamp: $current" | |
if [ "$last" = "$current" ]; then | |
continue | |
fi | |
_.run $* | |
last=$current | |
done | |
} | |
if [ $# -ne 2 ]; then | |
_.error "not enough arguments" | |
exit 1 | |
fi | |
TARGET_DIRECTORY=$1 | |
EXPECT_EMAIL=$2 | |
_.watch $TARGET_DIRECTORY $EXPECT_EMAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment