Commit ace17ee4 authored by cmosh's avatar cmosh

Git flow pause and resume

parent 46616541
...@@ -6,3 +6,5 @@ debian/*/* ...@@ -6,3 +6,5 @@ debian/*/*
.seconds .seconds
.seconds-feature-workingtime .seconds-feature-workingtime
.timelog-feature-workingtime .timelog-feature-workingtime
.seconds-feature-sdsa
.timelog-feature-sdsa
...@@ -40,11 +40,12 @@ init() { ...@@ -40,11 +40,12 @@ init() {
require_git_repo require_git_repo
require_gitflow_initialized require_gitflow_initialized
gitflow_load_settings gitflow_load_settings
parse_args "$@"
PREFIX=$(git config --get gitflow.prefix.feature) PREFIX=$(git config --get gitflow.prefix.feature)
} }
usage() { usage() {
echo "usage: git flow feature [list] [-v]" echo "usage: git flow feature [list] [-v] s"
echo " git flow feature start [-F] <name> [<base>]" echo " git flow feature start [-F] <name> [<base>]"
echo " git flow feature finish [-rFkDS] [<name|nameprefix>]" echo " git flow feature finish [-rFkDS] [<name|nameprefix>]"
echo " git flow feature publish <name>" echo " git flow feature publish <name>"
...@@ -53,6 +54,8 @@ usage() { ...@@ -53,6 +54,8 @@ usage() {
echo " git flow feature rebase [-i] [<name|nameprefix>]" echo " git flow feature rebase [-i] [<name|nameprefix>]"
echo " git flow feature checkout [<name|nameprefix>]" echo " git flow feature checkout [<name|nameprefix>]"
echo " git flow feature pull [-r] <remote> [<name>]" echo " git flow feature pull [-r] <remote> [<name>]"
echo " git flow feature pause <name>"
} }
cmd_default() { cmd_default() {
...@@ -198,6 +201,7 @@ cmd_start() { ...@@ -198,6 +201,7 @@ cmd_start() {
parse_args "$@" parse_args "$@"
BASE=${2:-$DEVELOP_BRANCH} BASE=${2:-$DEVELOP_BRANCH}
require_name_arg require_name_arg
echo ".seconds-feature-$NAME\n.timelog-feature-$NAME" >> .gitignore
# sanity checks # sanity checks
require_branch_absent "$BRANCH" require_branch_absent "$BRANCH"
...@@ -218,6 +222,20 @@ cmd_start() { ...@@ -218,6 +222,20 @@ cmd_start() {
die "Could not create feature branch '$BRANCH'" die "Could not create feature branch '$BRANCH'"
fi fi
echo "How long do you think this feature will take(in hours)?"
read TIME_REQUIRED
echo $TIME_REQUIRED >> ".timelog-feature-$NAME"
git add .gitignore
git commit --allow-empty -m "Started working on $BRANCH on $(date) estimated Time $TIME_REQUIRED"
echo $(date +%s) >> ".timelog-feature-$NAME"
echo echo
echo "Summary of actions:" echo "Summary of actions:"
echo "- A new branch '$BRANCH' was created, based on '$BASE'" echo "- A new branch '$BRANCH' was created, based on '$BASE'"
...@@ -251,7 +269,7 @@ cmd_finish() { ...@@ -251,7 +269,7 @@ cmd_finish() {
# TODO: git_is_clean_working_tree() should provide an alternative # TODO: git_is_clean_working_tree() should provide an alternative
# exit code for "unmerged changes in working tree", which we should # exit code for "unmerged changes in working tree", which we should
# actually be testing for here # actually be testing for
if git_is_clean_working_tree; then if git_is_clean_working_tree; then
FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE") FINISH_BASE=$(cat "$DOT_GIT_DIR/.gitflow/MERGE_BASE")
...@@ -340,6 +358,14 @@ cmd_finish() { ...@@ -340,6 +358,14 @@ cmd_finish() {
exit 1 exit 1
fi fi
TOTAL_TIME=awk '{ sum += $1 } END { print sum }' .seconds-feature-$NAME
TIME_EXPECTED=line=$(head -n 1 .timelog-feature-$NAME)
seconds=$TOTAL_TIME; FINALTIME=$((seconds/86400))" days "$(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds")
git commit --allow-empty -m "$BRANCH was completed on $(date), total time taken:$FINALTIME expectde time was $TIME_EXPECTED"
# when no merge conflict is detected, just clean up the feature branch # when no merge conflict is detected, just clean up the feature branch
helper_finish_cleanup helper_finish_cleanup
} }
...@@ -528,3 +554,82 @@ cmd_pull() { ...@@ -528,3 +554,82 @@ cmd_pull() {
echo "Created local branch $BRANCH based on $REMOTE's $BRANCH." echo "Created local branch $BRANCH based on $REMOTE's $BRANCH."
fi fi
} }
cmd_pause() {
parse_args "$@"
require_name_arg
# sanity checks
require_branch "$BRANCH"
require_branch_absent "$BRANCH-paused"
echo $(date +%s) >> ".timelog-feature-$NAME"
LAST_LINE="$(wc -l < .timelog-feature-$NAME)"
PREV_LINE=$((LAST_LINE-1))
LAST_TIME=$(sed "${LAST_LINE}q;d" .timelog-feature-$NAME)
PREV_TIME=$(sed "${PREV_LINE}q;d" .timelog-feature-$NAME)
TIME_USED=$((LAST_TIME-PREV_TIME))
echo "$TIME_USED" >> ".seconds-feature-$NAME"
seconds=$TIME_USED; TIMESTAMP=$((seconds/86400))" days "$(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds")
git add --all .
git commit -m "$BRANCH/WIP"
git commit --allow-empty -m "$BRANCH/WIP time-paused:$(date), time taken thus far:$TIMESTAMP"
git checkout --orphan "$BRANCH-paused"
echo
echo "Summary of actions:"
echo "- Created orphan branch called '$BRANCH-paused'"
echo "- You are now free to take a break, you have spent $TIMESTAMP in this session"
echo ""
echo "Now, have some coffee and when you are done, use:"
echo ""
echo " git flow feature resume $BRANCH"
echo
}
cmd_resume() {
parse_args "$@"
require_name_arg
# sanity checks
require_branch "$BRANCH"
git checkout "$BRANCH"
git branch -D "$BRANCH-paused"
git commit --allow-empty -m "$BRANCH/Back to Work at:$(date)"
echo $(date +%s) >> ".timelog-feature-$NAME"
echo
echo "Summary of actions:"
echo "Switches you back to the '$BRANCH' branch"
echo "- You are now on branch '$BRANCH'"
echo ""
echo "Remmember when you need a break use:"
echo ""
echo " git flow feature pause $NAME"
echo
}
\ No newline at end of file
...@@ -43,7 +43,7 @@ usage() { ...@@ -43,7 +43,7 @@ usage() {
} }
cmd_default() { cmd_default() {
echo "$GITFLOW_VERSION" echo "$GITFLOW_VERSION dreidev"
} }
cmd_help() { cmd_help() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment