Skip to content

Commit

Permalink
Various Improvements
Browse files Browse the repository at this point in the history
Feature: Added ability to leave a feature branch after finishing
Hotfix: Added ability to finish a hotfix branch without merging back to master
All: Added Hooks
  • Loading branch information
mrkmg committed Dec 30, 2016
1 parent f18bbaf commit 626a36d
Show file tree
Hide file tree
Showing 27 changed files with 626 additions and 59 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ decided I would build my own "git-flow".

The name "Git Stream" was chosen as this plugin should streamline some of the repetitious actions in git.

**Warning**

Git Stream is still very new, with minimal testing by a single person so far. While I am open to suggestions, bug
reports, etc, know that this project is a long way away from being ready for real use. As the project matures, this
warning will be updated.

[TOC levels=2-4]: # "#### Table of Contents"
#### Table of Contents
Expand All @@ -24,6 +19,7 @@ warning will be updated.
- [hotfix](#hotfix)
- [feature](#feature)
- [release](#release)
- [Hooks](#hooks)
- [Example](#example)
- [Recommendations](#recommendations)
- [Other Notes](#other-notes)
Expand Down Expand Up @@ -51,7 +47,7 @@ Example Installation on Linux
make test
sudo make install

By default, git-stream will be installed to `/usr/local/bin`. If you would prefer to install somewhere else, you can
By default, Git Stream will be installed to `/usr/local/bin`. If you would prefer to install somewhere else, you can
change the prefix. for example:

sudo make install PREFIX=/usr
Expand Down Expand Up @@ -81,12 +77,13 @@ Initialize Git Stream on the current project.
Work with hotfixes. Hotfixes are used to fix a bug in a release.

start {version} {hotfix-name}
finish [-l | -m {message} | -n] {versioned-hotfix-name} {new-version}
finish [-l -m {message} -n] {versioned-hotfix-name} {new-version}
list

-m, --message {message} A message for the merge (Implies -n)
-n, --no-ff Force a non fast-forward merge
-l, --leave Do not merge the hotfix back into the working branch
-d, --no-merge Do not merge the hotfix branch back into the working branch (Implies -l)
-l, --leave Do not remove the hotfix branch

`-l/--leave` is useful when hot-fixing an LTS version which is no longer relevant to the working branch

Expand All @@ -95,25 +92,39 @@ Work with hotfixes. Hotfixes are used to fix a bug in a release.
Work with features. Features are used to implement new functionality.

start {feature-name}
finish [-m {message} | -n] {feature-name}
finish [-m {message} -n] {feature-name}
list

-m, --message {message} A message for the merge (Implies -n)
-n, --no-ff Force a non fast-forward merge
-l, --leave Do not remove the feature branch

#### release

Work with releases. Releases are used to mark specific versions.

start {version}
finish [-l | -m {message} | -n] {version}
finish [-l -m {message} -n -d] {version}
list

-m, --message {message} A message for the merge (Implies -n)
-n, --no-ff Force a non fast-forward merge
-l, --leave Do not remove the release branch
-d, --no-merge Do not merge the release branch back into the working branch

### Hooks

Git Stream will run hook in the .git/hooks directory. In order to see boilerplate scripts, look at the support/hooks
directory.

Any "pre" hook which returns a non-zero status will halt the operation. "post" hooks exit codes are not examined and
will not affect the action from running.

The available hooks are: `post-stream-feature-finish`, `post-stream-feature-start`, `post-stream-hotfix-finish`,
`post-stream-hotfix-start`, `post-stream-release-finish`, `post-stream-release-start`, `pre-stream-feature-finish`,
`pre-stream-feature-start`, `pre-stream-hotfix-finish`, `pre-stream-hotfix-start`, `pre-stream-release-finish`, and
`pre-stream-release-start`

## Example

The following is a contrived example of working on a library with Git Stream.
Expand Down Expand Up @@ -146,8 +157,8 @@ After you finish writing the new feature, go ahead and finish up the feature.
git stream feature finish new-feature

If you run into the message `Failed to merge feature/new-feature into master.`, that means you can not simply merge the
feature into master as master has been changed. This can often happen if multiple features are being finished. The fix
is very easy. Rebase master into your new feature branch.
feature into master. This can often happen if multiple features are being finished. The fix is very easy. Rebase master
into your new feature branch.

While on the feature/new-feature branch, run the following commands:

Expand Down Expand Up @@ -175,7 +186,7 @@ This should not have any conflicts, but if it does you can rebase like you did w
release back into master and create a tag for the version. At this point you probably would want to publish the version,
so you can do that as simply as:

git push origin --tags
git push origin && git push origin --tags

The last feature is the hotfix. Lets say some time goes by, you have committed to master a few times, started a couple
new features, but then a bug is reported that needs an immediate fix. This is where Hot Fixes come into play. If back in
Expand Down Expand Up @@ -212,7 +223,7 @@ Make the proper corrections, stage them, then make a commit.

## Other Notes

For an automated deployment, you may want to checkout the latest release. _If you only use tags for release, you can
For an automated deployment, you may want to checkout the latest release. _If you only use tags for release, you can
easily accomplish this with:_

git checkout $(git describe --abbrev=0 --tags)
Expand Down
9 changes: 5 additions & 4 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#Git Stream Road Map

- Messages on release
- Documentation
- Testing, Testing, Testing (automated tests would be best)
- ~~Messages on release~~
- ~~Documentation~~
- ~~Testing, Testing, Testing (automated tests would be best)~~
- More feature parity with gitflow
- Hooks

There will most likely be much more added to this list as time goes on.
There will most likely be much more added to this list as time goes on.
47 changes: 46 additions & 1 deletion bin/git-stream
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,51 @@ gitstream_merge() {
fi
}

gitstream_run_hook() {
local hook_dir script stage type action

stage="$1"; shift
type="$1"; shift
action="$1"; shift

hook_dir="$(git rev-parse --git-dir)/hooks"
script="${hook_dir}/${stage}-stream-${type}-${action}"

if [ -x "$script" ]; then
if [ ${GITSTREAM_DEBUG} -eq 1 ]; then
echo "Running ${script} $@" >&2
fi

"$script" "$@"

return 0
fi
}

gitstream_run_hook_die() {
local hook_dir script stage type action

stage="$1"; shift
type="$1"; shift
action="$1"; shift

hook_dir="$(git rev-parse --git-dir)/hooks"
script="${hook_dir}/${stage}-stream-${type}-${action}"

if [ -x "$script" ]; then
if [ ${GITSTREAM_DEBUG} -eq 1 ]; then
echo "Running ${script} $@" >&2
fi

"$script" "$@"

if [ "$?" -gt 0 ]; then
print_error "The hook ${script} exited with $?"
exit 1
fi
fi
}

gitstream_source() {
local command command_type file func

Expand Down Expand Up @@ -232,4 +277,4 @@ main() {
gitstream_${sub_command} "$@"
}

main "$@"
main "$@"
10 changes: 8 additions & 2 deletions bin/git-stream-feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ usage() {
echo "Available subcommands are:"
echo
echo "start {feature-name}"
echo "finish [-m {message} | -n] {feature-name}"
echo "finish [-l | -m {message} | -n] {feature-name}"
echo "list"
echo
echo "-m, --message {message} A message for the merge (Implies -n)"
echo "-n, --no-ff Force a non fast-forward merge"
echo "-l, --leave Do not delete the feature branch"
}

gitstream_feature() {
Expand All @@ -32,6 +33,7 @@ gitstream_feature() {

GITSTREAM_FEATURE_MESSAGE=""
GITSTREAM_FEATURE_NOFF=0
GITSTREAM_FEATURE_LEAVE=0

while arg=$1 && [ "${arg:0:1}" == "-" ]; do
case ${arg} in
Expand All @@ -41,7 +43,11 @@ gitstream_feature() {
;;
"-n"|"--no-ff")
shift
GITSTREAM_HOTFIX_NOFF=1;
GITSTREAM_FEATURE_NOFF=1
;;
"-l"|"--leave")
shift
GITSTREAM_FEATURE_LEAVE=1
;;
*)
usage; exit 1
Expand Down
14 changes: 10 additions & 4 deletions bin/git-stream-feature-finish
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gitstream_feature_finish() {
feature="$1"
branch="${FEATURE_PREFIX}${feature}"

gitstream_run_hook_die pre feature finish "${feature}" "${branch}" "${WORKING_BRANCH}"

if [ ${GITSTREAM_FEATURE_NOFF} -eq 1 ] || [ ${#GITSTREAM_FEATURE_MESSAGE} -gt 0 ]; then
merge_args="${merge_args} --no-ff"
fi
Expand All @@ -19,11 +21,15 @@ gitstream_feature_finish() {

gitstream_merge "${branch}" "${WORKING_BRANCH}" ${merge_args}

if ! do_git branch -d ${branch}; then
print_error "Failed to remove ${branch}"
exit 1
if [ ${GITSTREAM_FEATURE_LEAVE} -eq 0 ]; then
if ! do_git branch -d ${branch}; then
print_error "Failed to remove ${branch}"
exit 1
fi
fi

gitstream_run_hook post feature finish "${feature}" "${branch}" "${WORKING_BRANCH}"

echo
echo "Feature ${feature} has been merged into ${WORKING_BRANCH}"
}
}
6 changes: 5 additions & 1 deletion bin/git-stream-feature-start
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ gitstream_feature_start() {
feature="$1"
branch="${FEATURE_PREFIX}${feature}"

gitstream_run_hook_die pre feature start "${feature}" "${branch}" "${WORKING_BRANCH}"

if git_rev_exists ${branch}; then
print_error "Branch ${branch} already exists"
exit 1
fi

gitstream_make_branch "${WORKING_BRANCH}" "${branch}"

gitstream_run_hook post feature start "${feature}" "${branch}" "${WORKING_BRANCH}"

echo
echo "Your are now on ${branch}. When you are done with the feature, run git stream feature finish ${feature}"
}
}
16 changes: 11 additions & 5 deletions bin/git-stream-hotfix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ usage() {
echo
echo "-m, --message {message} A message for the merge (Implies -n)"
echo "-n, --no-ff Force a non fast-forward merge"
echo "-l, --leave Do not merge the hotfix back into the working branch"
echo "-d, --no-merge Do not merge the hotfix branch back into the working branch"
echo "-l, --leave Do not delete the hotfix branch"
}

gitstream_hotfix() {
Expand All @@ -33,7 +34,8 @@ gitstream_hotfix() {

GITSTREAM_HOTFIX_MESSAGE=""
GITSTREAM_HOTFIX_NOFF=0
GITSTREAM_HOTFIX_MERGE=1
GITSTREAM_HOTFIX_NOMERGE=0
GITSTREAM_HOTFIX_LEAVE=0

while arg=$1 && [ "${arg:0:1}" == "-" ]; do
case ${arg} in
Expand All @@ -43,11 +45,15 @@ gitstream_hotfix() {
;;
"-n"|"--no-ff")
shift
GITSTREAM_HOTFIX_NOFF=1;
GITSTREAM_HOTFIX_NOFF=1
;;
"-l"|"--leave")
shift
GITSTREAM_HOTFIX_MERGE=0;
GITSTREAM_HOTFIX_LEAVE=1
;;
"-d"|"--no-merge")
shift
GITSTREAM_HOTFIX_NOMERGE=1
;;
*)
usage; exit 1
Expand All @@ -58,4 +64,4 @@ gitstream_hotfix() {
gitstream_source "hotfix-${sub_command}"

gitstream_hotfix_${sub_command} "$@"
}
}
21 changes: 15 additions & 6 deletions bin/git-stream-hotfix-finish
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ gitstream_hotfix_finish() {

branch="${HOTFIX_PREFIX}${hotfix}"

gitstream_run_hook_die pre hotfix finish "${hotfix}" "${branch}" "${WORKING_BRANCH}"

if git_rev_exists ${new_prefixed_version}; then
print_error "The tag ${new_prefixed_version} already exists."
exit 1
Expand All @@ -37,8 +39,9 @@ gitstream_hotfix_finish() {

gitstream_checkout_branch ${WORKING_BRANCH}

if [ ${GITSTREAM_HOTFIX_MERGE} -eq 1 ]; then


if [ ${GITSTREAM_HOTFIX_NOMERGE} -eq 0 ]; then
if [ ${GITSTREAM_HOTFIX_NOFF} -eq 1 ] || [ ${#GITSTREAM_HOTFIX_MESSAGE} -gt 0 ]; then
merge_args="${merge_args} --no-ff"
fi
Expand All @@ -52,10 +55,16 @@ gitstream_hotfix_finish() {
echo "${hotfix} has been applied to master."
fi

if ! do_git branch -D ${branch}; then
print_error "Failed to remove ${branch}"
bug_error_message
exit 1
if [ ${GITSTREAM_HOTFIX_LEAVE} -eq 0 ]; then
if ! do_git branch -D ${branch}; then
print_error "Failed to remove ${branch}"
bug_error_message
exit 1
fi

echo "${branch} has been deleted.";
fi

}
gitstream_run_hook post hotfix finish "${hotfix}" "${branch}" "${WORKING_BRANCH}"

}
10 changes: 8 additions & 2 deletions bin/git-stream-hotfix-start
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ gitstream_hotfix_start() {

branch="${HOTFIX_PREFIX}${version}-${hotfix}"

gitstream_run_hook_die pre hotfix start "${hotfix}" "${branch}" "${WORKING_BRANCH}" "${source_tag}"


if ! git_rev_exists ${source_tag}; then
print_error "No tag for version ${source_tag}"
exit 1
Expand All @@ -28,8 +31,11 @@ gitstream_hotfix_start() {
exit 1
fi

gitstream_make_branch "${WORKING_BRANCH}" "${branch}"
gitstream_make_branch "${source_tag}" "${branch}"

gitstream_run_hook post hotfix start "${hotfix}" "${branch}" "${WORKING_BRANCH}" "${source_tag}"


echo
echo "Your are now on ${branch}. When you are done with the hotfix, run git stream hotfix finish ${version} ${hotfix}"
}
}
Loading

0 comments on commit 626a36d

Please sign in to comment.