create push subcommand and stat option for add subcommand

This commit is contained in:
Motonori Iwata 2011-10-18 01:24:16 +09:00
parent b62c661744
commit 8bc6bffcb6
9 changed files with 67 additions and 23 deletions

View file

@ -21,7 +21,8 @@ You can use the same option as ``git add``.
Available subcommands are: Available subcommands are:
* rebase - rebase for temporary commits. * rebase - rebase for temporary commits.
* grep - grep temporary commits. * push - rebuild remote branch after rebase.
* grep - grep temporary commits.
_Try 'git now \<subcommand\> help' for details._ _Try 'git now \<subcommand\> help' for details._

View file

@ -24,6 +24,7 @@ __git-now-add ()
'-e[open diff against index in editor]'\ '-e[open diff against index in editor]'\
'-u[update only files git already knows about]'\ '-u[update only files git already knows about]'\
'-N[record only that path will be added later]'\ '-N[record only that path will be added later]'\
'-s[generate diffstat instead of patch]'\
':filepattern:_files' ':filepattern:_files'
} }
@ -76,6 +77,7 @@ case $state in
subcommands=( subcommands=(
'add:default subcommand.' 'add:default subcommand.'
'rebase:rebase for temporary commits.' 'rebase:rebase for temporary commits.'
'push:remove remote branch and push to remote repoistory for rebase commits.'
'grep:grep temporary commits.' 'grep:grep temporary commits.'
) )
_describe -t commands 'git now' subcommands _describe -t commands 'git now' subcommands
@ -95,6 +97,11 @@ case $state in
':branch-name:__git_branch_names' ':branch-name:__git_branch_names'
;; ;;
(push)
_arguments \
':remote-repostory:__git_remotes'
;;
(grep) (grep)
_arguments \ _arguments \
'-p[generate diff in patch format]'\ '-p[generate diff in patch format]'\

View file

@ -34,6 +34,7 @@ _git-now ()
subcommands=( subcommands=(
'add:default subcommand.' 'add:default subcommand.'
'rebase:rebase for temporary commits.' 'rebase:rebase for temporary commits.'
'push:remove remote branch and push to remote repoistory for rebase commits.'
'grep:grep temporary commits.' 'grep:grep temporary commits.'
) )
_describe -t commands 'git now' subcommands _describe -t commands 'git now' subcommands
@ -53,6 +54,11 @@ _git-now ()
':branch-name:__git_branch_names' ':branch-name:__git_branch_names'
;; ;;
(push)
_arguments \
':remote-repostory:__git_remotes'
;;
(grep) (grep)
_arguments \ _arguments \
'-p[generate diff in patch format]'\ '-p[generate diff in patch format]'\
@ -82,6 +88,7 @@ __git-now-add ()
'-e[open diff against index in editor]'\ '-e[open diff against index in editor]'\
'-u[update only files git already knows about]'\ '-u[update only files git already knows about]'\
'-N[record only that path will be added later]'\ '-N[record only that path will be added later]'\
'-s[generate diffstat instead of patch]'\
':filepattern:_files' ':filepattern:_files'
} }

View file

@ -19,6 +19,7 @@ usage() {
echo "Available subcommands are:" echo "Available subcommands are:"
echo " add default subcommand." echo " add default subcommand."
echo " rebase rebase for temporary commits." echo " rebase rebase for temporary commits."
echo " push remove remote branch before push to remote repoistory for rebase commits."
echo " grep grep temporary commits." echo " grep grep temporary commits."
echo echo
echo "Try 'git now <subcommand> help' for details." echo "Try 'git now <subcommand> help' for details."

View file

@ -1,7 +1,7 @@
usage() { usage() {
echo "usage: git now add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]" echo "usage: git now add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]"
echo " [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]" echo " [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]"
echo " [--refresh] [--ignore-errors] [--ignore-missing] [--]" echo " [--refresh] [--ignore-errors] [--ignore-missing] [ --stat | -s ] [--]"
echo " [<filepattern>...]" echo " [<filepattern>...]"
} }
@ -11,13 +11,32 @@ cmd_default() {
git add -u git add -u
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F - printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
else else
local is_stat=false
local args=()
# args loop
for arg in "$@"
do
if [ $arg = "--stat" ] || [ $arg = "-s" ]; then
is_stat=true
else
n=${#args[@]}
args[$n]=$arg
fi
done
if [ $1 != "--all" ]; then if [ $1 != "--all" ]; then
git add $@ git add ${args[@]}
else else
git add -u git add -u
git add . git add .
fi fi
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
if $is_stat; then
printf "${MESSAGE}\n\n%s" "`git diff --cached --stat`" | git commit -F -
else
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
fi
fi fi
} }
@ -26,3 +45,4 @@ cmd_help() {
exit 0 exit 0
} }
# vim: set ff=unix ft=sh :

View file

@ -41,3 +41,4 @@ cmd_help() {
exit 0 exit 0
} }
# vim: set ff=unix ft=sh :

23
git-now-push Normal file
View file

@ -0,0 +1,23 @@
usage() {
echo "usage: git now push [<remote-repository>]"
}
cmd_default() {
REMOTE=$1
WORKING_BRANCH=$(git_current_branch)
if [ -n "$REMOTE" ]; then
git push ${REMOTE} :${WORKING_BRANCH} && git push ${REMOTE} ${WORKING_BRANCH}
else
git push origin :${WORKING_BRANCH} && git push
fi
}
cmd_help() {
usage
exit 0
}
# vim: set ff=unix ft=sh :

View file

@ -1,8 +1,5 @@
usage() { usage() {
echo "usage: git now rebase [--mine|-m] [<base-branch>]" echo "usage: git now rebase [--mine|-m] [<base-branch>]"
#echo " git now rebase --push [<base-branch>]"
#echo " git now rebase --push --upstream <remote> [<base-branch>]"
#echo " git now rebase --push --remove <remote> [<base-branch>]"
} }
@ -42,17 +39,6 @@ cmd_default() {
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH} git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
fi fi
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() { cmd_help() {
@ -63,15 +49,11 @@ cmd_help() {
parse_args() { parse_args() {
# parse options # parse options
DEFINE_boolean 'mine' false 'limit git-now commits by my name' 'm' DEFINE_boolean 'mine' false 'limit git-now commits by my name' 'm'
#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 $? FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}" eval set -- "${FLAGS_ARGV}"
# read arguments into global variables # read arguments into global variables
BASE_BRANCH=$1 BASE_BRANCH=$1
#UPSTREAM_REMOTE=$FLAGS_upstream
#REMOVE_REMOTE=$FLAGS_remove
} }
# vim: set ff=unix ft=sh :

View file

@ -60,3 +60,5 @@ git_now_my_first_commit() {
} }
git_now_initial_commit() { git log --pretty=oneline | tail -n 1 | cut -d " " -f 1; } git_now_initial_commit() { git log --pretty=oneline | tail -n 1 | cut -d " " -f 1; }
# vim: set ff=unix ft=sh