1 2 3 4 | $ cd . /gitpath/hogehoge $ git add . $ git commit $ git push |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #! /bin/bash # # Auto git update tool # 2011/06/05 Ver:1.3 joey chen # # # check depend commands # _dependCommands= "git expect" for _COMMAND in ${_dependCommands}; do if [ ! ` whereis ${_COMMAND} | grep ${_COMMAND}` ]; then echo "ERROR!! 必要なコマンドが見つかりません : ${_COMMAND}" exit 1 fi done # # check args # if [ $ # -eq 0 ]; then cat <<_EOF_ Auto git pull /push Tool 実行中のディレクトリ配下にある複数あるgitディレクトリを一気に 更新(commit /pull/push )するツールです。 使い方 sh . /updateGit .sh [commit|pull|push|status] [remote name] [branch name] 各ディレクトリの ./*/.git を探して、有る場合に指定の git のコマンドを実行します。 オプションは以下のいずれかを選ぶ必要があります。 commit : add を実行してから commit します。 status : git status 処理を実施します。 pull : 指定した remote からpullします。初回のみパスワード入力を促されます。 push : 指定した remote からpushします。初回のみパスワード入力を促されます。 ※ branch name を指定していない場合は、自動で master で処理します。 _EOF_ exit 1 fi # # check args 2nd # if [ \( $1 != 'pull' \) -a \( $1 != 'push' \) -a \( $1 != 'commit' \) -a \( $1 != 'status' \) ]; then echo "ERROR!! 正しい引数を指定してください。" exit 1 fi if [ \( \( $1 = 'pull' \) -o \( $1 = 'push' \) \) -a \( $ # -eq 1 \) ]; then echo "ERROR!! push か pull を実行する際は、第2引数(remote 識別子)を指定してください。" exit 1 fi # # Get git dirs # _GITDIRS=` find . -name ".git" | sed "s/\(\.\/.*\)\/.git/\1/g" ` # # show status # if [ $1 == 'status' ]; then for _DIRS in ${_GITDIRS}; do echo -e "\n -- ${_DIRS} -- " ; cd $_DIRS; git status; cd ../ done fi # # Update Git Dirs # ## COMMIT if [ $1 == 'commit' ]; then # update dirs for _DIRS in ${_GITDIRS}; do echo -e "\n -- ${_DIRS} -- " ; cd $_DIRS; git add -u; git add .; git commit -m "auto Update by Script at `date`" ; cd ../ done fi ## PUSH or PULL if [ \( $1 == 'push' \) -o \( $1 == 'pull' \) ]; then if [ $ # -eq 2 ]; then _COMMAND=$1 _REMOTE=$2 _BRANCH= "master" fi if [ $ # -eq 3 ]; then _COMMAND=$1 _REMOTE=$2 _BRANCH=$3 fi # get password stty - echo read -p "Password: " _PW; echo stty echo # update dirs for _DIRS in ${_GITDIRS}; do echo -e "\n -- ${_DIRS} -- " ; cd $_DIRS; expect -c " set timeout 10 spawn git ${_COMMAND} ${_REMOTE} ${_BRANCH} expect password:\ ; send \"${_PW}\r\" interact " cd ../ done fi |
2013/07/15 渋川氏のアドバイスで一部修正
1 2 3 4 5 6 7 8 9 10 11 12 13 | diff --git a /updateGit .sh b /updateGit .sh index ab53aa9..c0e2a0b 100755 --- a /updateGit .sh +++ b /updateGit .sh @@ -58,7 +58,7 @@ fi # # Get git dirs # -_GITDIRS=` find . - type d -name ".git" | sed "s/\(\.\/.*\)\/.git/\1/g" ` +_GITDIRS=` find . -name ".git" | sed "s/\(\.\/.*\)\/.git/\1/g" ` # # show status |