From 3864632dff51a4df965644d090dedf6fb100df94 Mon Sep 17 00:00:00 2001 From: Motonori Iwata Date: Mon, 12 Sep 2011 13:34:09 +0900 Subject: [PATCH] =?UTF-8?q?z=20*=20rebase,=20grep=E3=81=ABauthor=E3=82=AA?= =?UTF-8?q?=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=20=20=20*=20rebase=E3=81=AEpush=E3=82=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git-now-grep | 7 ++++++- git-now-rebase | 51 +++++++++++++++++++++++++++++--------------------- gitnow-common | 10 ++++++++++ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/git-now-grep b/git-now-grep index f562023..27de185 100644 --- a/git-now-grep +++ b/git-now-grep @@ -1,5 +1,5 @@ usage() { - echo "usage: git now grep [--patch|-p] [--stat|-s] []" + echo "usage: git now grep [--patch|-p] [--stat|-s] [--author|-a] []" } cmd_default() { @@ -18,6 +18,7 @@ parse_args() { # parse options DEFINE_boolean 'patch' false 'generate diff in patch format' 'p' DEFINE_boolean 'stat' false 'generate diffstat instead of patch' 's' + DEFINE_boolean 'author' false 'limit git-now commits by your name' 'a' FLAGS "$@" || exit $? eval set -- "${FLAGS_ARGV}" # read arguments into global variables @@ -29,6 +30,10 @@ parse_args() { if flag stat; then ARGS="${ARGS} --stat" fi + if flag author; then + AUTHOR=$(escape `git config --get user.name`) + ARGS="${ARGS} --author=$AUTHOR" + fi } cmd_help() { diff --git a/git-now-rebase b/git-now-rebase index 7b4e9ef..e3078eb 100644 --- a/git-now-rebase +++ b/git-now-rebase @@ -1,8 +1,8 @@ usage() { - echo "usage: git now rebase []" - echo " git now rebase --push []" - echo " git now rebase --push --upstream []" - echo " git now rebase --push --remove []" + echo "usage: git now rebase [--author|-a] []" + #echo " git now rebase --push []" + #echo " git now rebase --push --upstream []" + #echo " git now rebase --push --remove []" } @@ -14,7 +14,11 @@ cmd_default() { if [ -n "$BASE_BRANCH" ]; then COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}` - FIRST_NOW_COMMIT=$(git_now_first_commit $COMMON_ANCESTOR_COMMIT) + if flag author; then + FIRST_NOW_COMMIT=$(git_now_my_first_commit $COMMON_ANCESTOR_COMMIT) + else + FIRST_NOW_COMMIT=$(git_now_first_commit $COMMON_ANCESTOR_COMMIT) + fi if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then git rebase -i ${FIRST_NOW_COMMIT}^ @@ -24,7 +28,11 @@ cmd_default() { git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH} fi else - FIRST_NOW_COMMIT=$(git_now_first_commit) + if flag author; then + FIRST_NOW_COMMIT=$(git_now_my_first_commit) + else + FIRST_NOW_COMMIT=$(git_now_first_commit) + fi if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then git rebase -i ${FIRST_NOW_COMMIT}^ @@ -35,16 +43,16 @@ cmd_default() { fi fi - if flag push; then - if [ -n "$UPSTREAM_REMOTE" ]; then - git push --set-upstream $UPSTREAM_REMOTE $WORKING_BRANCH - elif [ -n "$REMOVE_REMOTE" ]; then - git push $REMOVE_REMOTE :$WORKING_BRANCH - git push - else - git push - fi - fi + #if flag push; then + #if [ -n "$UPSTREAM_REMOTE" ]; then + #git push --set-upstream $UPSTREAM_REMOTE $WORKING_BRANCH + #elif [ -n "$REMOVE_REMOTE" ]; then + #git push $REMOVE_REMOTE :$WORKING_BRANCH + #git push + #else + #git push + #fi + #fi } cmd_help() { @@ -54,15 +62,16 @@ cmd_help() { parse_args() { # parse options - DEFINE_boolean 'push' false 'push to remote repository finally' '' - DEFINE_string 'remove' '' 'remote name to remove the remote branch before push' '' - DEFINE_string 'upstream' '' 'remote name for --set-upstream' '' + DEFINE_boolean 'author' false 'limit git-now commits by your name' 'a' + #DEFINE_boolean 'push' false 'push to remote repository finally' '' + #DEFINE_string 'remove' '' 'remote name to remove the remote branch before push' '' + #DEFINE_string 'upstream' '' 'remote name for --set-upstream' '' FLAGS "$@" || exit $? eval set -- "${FLAGS_ARGV}" # read arguments into global variables BASE_BRANCH=$1 - UPSTREAM_REMOTE=$FLAGS_upstream - REMOVE_REMOTE=$FLAGS_remove + #UPSTREAM_REMOTE=$FLAGS_upstream + #REMOVE_REMOTE=$FLAGS_remove } diff --git a/gitnow-common b/gitnow-common index aec7aff..409458f 100644 --- a/gitnow-common +++ b/gitnow-common @@ -49,4 +49,14 @@ git_now_first_commit() { fi } +git_now_my_first_commit() { + local author=$(escape `git config --get user.name`) + local common=$1 + if [ $# -eq 1 ]; then + git log ${common}.. --pretty=oneline --author=${author} --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1 + else + git log --pretty=oneline --author=${author} --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1 + fi +} + git_now_initial_commit() { git log --pretty=oneline | tail -n 1 | cut -d " " -f 1; }