create add and grep subcommand

This commit is contained in:
Motonori Iwata 2011-09-03 21:21:58 +09:00
parent 8ff8cdc54d
commit 871e22590e
7 changed files with 131 additions and 89 deletions

View file

@ -29,17 +29,18 @@
# Determine if we're inside a debian build ..
ifdef DEB_BUILD_ARCH
prefix=$(DESTDIR)/usr/
prefix=$(DESTDIR)/usr/
else
prefix=/usr/local
prefix=/usr/local
endif
# files that need mode 755
EXEC_FILES=git-now
# files that need mode 644
SCRIPT_FILES =git-now-rebase
SCRIPT_FILES+=git-now-update
SCRIPT_FILES =git-now-add
SCRIPT_FILES+=git-now-grep
SCRIPT_FILES+=git-now-rebase
SCRIPT_FILES+=gitnow-common
SCRIPT_FILES+=gitnow-shFlags
@ -54,5 +55,5 @@ install:
uninstall:
test -d $(prefix)/bin && \
cd $(prefix)/bin && \
rm -f $(EXEC_FILES) $(SCRIPT_FILES)
cd $(prefix)/bin && \
rm -f $(EXEC_FILES) $(SCRIPT_FILES)

94
git-now
View file

@ -2,88 +2,74 @@
# enable debug mode
if [ "$DEBUG" = "yes" ]; then
set -x
set -x
fi
export GITNOW_DIR=$(dirname "$0")
PREFIX="from now"
usage() {
echo "usage: git now [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]"
echo "usage: git now [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]"
echo " [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]"
echo " [--refresh] [--ignore-errors] [--ignore-missing] [--]"
echo " [<filepattern>...]"
echo
echo " git now <subcommand>"
echo
echo "Available subcommands are:"
echo " rebase rebase for temporary commits."
echo
echo "Try 'git now <subcommand> help' for details."
echo
echo "Available subcommands are:"
echo " add default subcommand."
echo " rebase rebase for temporary commits."
echo " grep grep temporary commits."
echo
echo "Try 'git now <subcommand> help' for details."
}
main() {
# load common functionality
. "$GITNOW_DIR/gitnow-common"
# load common functionality
. "$GITNOW_DIR/gitnow-common"
# This environmental variable fixes non-POSIX getopt style argument
# parsing, effectively breaking git-now subcommand parsing on several
# Linux platforms.
export POSIXLY_CORRECT=1
# This environmental variable fixes non-POSIX getopt style argument
# parsing, effectively breaking git-now subcommand parsing on several
# Linux platforms.
export POSIXLY_CORRECT=1
# use the shFlags project to parse the command line arguments
. "$GITNOW_DIR/gitnow-shFlags"
FLAGS_PARENT="git now"
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# use the shFlags project to parse the command line arguments
. "$GITNOW_DIR/gitnow-shFlags"
# sanity checks
SUBCOMMAND="$1"; shift
if [ ! -e "$GITNOW_DIR/git-now-$SUBCOMMAND" ]; then
SUBCOMMAND="$1"
if [ ! -e "$GITNOW_DIR/git-now-$SUBCOMMAND" ]; then
if [ "$SUBCOMMAND" = "help" ]; then
usage
exit 0
else
main_add "$@"
SUBCOMMAND="add"
fi
exit 0
fi
else
FLAGS_PARENT="git now"
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"; shift
# run command
. "$GITNOW_DIR/git-now-$SUBCOMMAND"
FLAGS_PARENT="git now $SUBCOMMAND"
FLAGS_PARENT="git now $SUBCOMMAND"
fi
# test if the first argument is a flag (i.e. starts with '-')
# in that case, we interpret this arg as a flag for the default
# command
# run command
. "$GITNOW_DIR/git-now-$SUBCOMMAND"
# test if the first argument is a flag (i.e. starts with '-')
# in that case, we interpret this arg as a flag for the default
# command
SUBACTION="default"
if [ "$1" = "help" ] && { ! echo "$1" | grep -q "^-"; } then
SUBACTION="$1"; shift
fi
#if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
#warn "Unknown subcommand: '$SUBACTION'"
#usage
#exit 1
#fi
#if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
#warn "Unknown subcommand: '$SUBACTION'"
#usage
#exit 1
#fi
# run the specified action
cmd_$SUBACTION "$@"
}
main_add() {
MESSAGE="[${PREFIX}] `date +\"%Y/%m/%d %T\"`"
if [ $# -eq 0 ]; then
echo "git add -u"
#printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
else
if [ $1 != "--all" ]; then
echo "git add $@"
else
echo "git add -u"
echo "git add ."
fi
#printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
fi
# run the specified action
cmd_$SUBACTION "$@"
}
main "$@"

28
git-now-add Normal file
View file

@ -0,0 +1,28 @@
usage() {
echo "usage: git now add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]"
echo " [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]"
echo " [--refresh] [--ignore-errors] [--ignore-missing] [--]"
echo " [<filepattern>...]"
}
cmd_default() {
MESSAGE="[${PREFIX}] `date +\"%Y/%m/%d %T\"`"
if [ $# -eq 0 ]; then
git add -u
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
else
if [ $1 != "--all" ]; then
git add $@
else
git add -u
git add .
fi
printf "${MESSAGE}\n\n%s" "`git diff --cached`" | git commit -F -
fi
}
cmd_help() {
usage
exit 0
}

29
git-now-grep Normal file
View file

@ -0,0 +1,29 @@
usage() {
echo "usage: git now grep [<base_branch>]"
}
cmd_default() {
parse_args "$@"
if [ -n "$BASE_BRANCH" ]; then
WORKING_BRANCH=$(git_current_branch)
COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}`
echo `git log ${COMMON_ANCESTOR_COMMIT}.. --pretty=oneline --grep="${PREFIX}"`
else
echo `git log --pretty=oneline --grep="${PREFIX}"`
fi
}
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
BASE_BRANCH=$1
}
cmd_help() {
usage
exit 0
}

26
git-now-rebase Executable file → Normal file
View file

@ -1,6 +1,6 @@
usage() {
echo "usage: git now rebase [<base_branch>]"
echo " git now rebase -p [-r <remote>] [<base_branch>]"
echo " git now rebase --push|-p [--remote|-r <remote>] [<base_branch>]"
}
@ -15,21 +15,21 @@ cmd_default() {
FIRST_NOW_COMMIT=$(git_now_first_commit $COMMON_ANCESTOR_COMMIT)
if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then
echo "git rebase -i ${FIRST_NOW_COMMIT}^"
git rebase -i ${FIRST_NOW_COMMIT}^
else
echo "git checkout ${FIRST_NOW_COMMIT}"
echo "git commit --amend"
echo "git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}"
git checkout ${FIRST_NOW_COMMIT}
git commit --amend
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
fi
else
FIRST_NOW_COMMIT=$(git_now_first_commit)
if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then
echo "git rebase -i ${FIRST_NOW_COMMIT}^"
git rebase -i ${FIRST_NOW_COMMIT}^
else
echo "git checkout ${FIRST_NOW_COMMIT}"
echo "git commit --amend"
echo "git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}"
git checkout ${FIRST_NOW_COMMIT}
git commit --amend
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
fi
fi
@ -45,8 +45,8 @@ cmd_help() {
parse_args() {
# parse options
DEFINE_boolean push false 'push to remote repository finally' 'p'
DEFINE_string remote '' 'remote branch name to --set-upstream' 'r'
DEFINE_boolean 'push' false 'push to remote repository finally' 'p'
DEFINE_string 'remote' '' 'remote branch name to --set-upstream' 'r'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
@ -59,9 +59,9 @@ _cmd_push() {
local branch=$1
local remote=$2
if [ -n "$remote" ]; then
echo "git push --set-upstream ${remote} ${branch}"
git push --set-upstream ${remote} ${branch}
else
echo "git push"
git push
fi
}

View file

@ -1,12 +0,0 @@
#!/bin/sh
PREFIX="from now"
if [ ! "`git log --pretty=oneline $3 | head -n 1 | grep "${PREFIX}"`" ]
then
exit 0
else
echo "error: There are tmp log messages in the received objects." 1>&2
echo "error: Change these messages by 'git now --rebase'." 1>&2
exit 1
fi

View file

@ -1,7 +1,17 @@
require 'formula'
class GitNow < GithubGistFormula
url 'https://gist.github.com/raw/1167062/03c52077ce8c7fb72537bdf9cbd50bd11f3a9d5c/git-now'
md5 '72a36ca8deb21b7cc26b8a8f5dc3e7be'
homepage 'https://gist.github.com/1167062'
class GitNow < Formula
url 'https://github.com/nvie/gitflow.git', :tag => 'v0.0.1'
version '0.0.1'
head 'https://github.com/iwata/git-now.git', :branch => 'develop'
homepage 'https://github.com/iwata/git-now'
# for longopt
depends_on 'gnu-getopt'
def install
system "make", "prefix=#{prefix}", "install"
system "brew ln gnu-getopt"
end
end