-
Notifications
You must be signed in to change notification settings - Fork 64
Custom Workflows
Git-reflow's default process isn't meant to fit every team, which is why we've introduced Workflows
.
As of git-reflow versions >= 0.9.0
, you can use a special file that can contain customizations to the default process. With this, you can:
- Add hooks to be run
before
, orafter
anycommand
- Use one of our pre-configured workflows as a basis for your own
- Override any of the default commands
- Create new commands
Examples:
# Use a pre-defined workflow
use "FlatMergeWorkflow"
# Do something before the `start` command
before :start do
say "Booya! Started this bad girl."
end
# Do something after the `deliver` command
after :deliver do
run "say 'Well done!'"
end
# Override the `start` command to auto-name feature branches
command :start, arguments: { feature_branch: nil }, flags: { base: 'dev' }, switches: { loud: false } do |**params|
base_branch = params[:base]
feature_branch = params[:feature_branch] || "feature-#{Time.now.strftime("%Y-%m-%d")}"
run_command_with_label "git checkout #{base_branch}"
run_command_with_label "git pull origin #{base_branch}"
run_command_with_label "git push origin #{base_branch}:refs/heads/#{feature_branch}"
run_command_with_label "git checkout --track -b #{feature_branch} origin/#{feature_branch}"
end
# Create a new command
command :boom do
GitReflow.say "Boom."
end
The block that you pass to each of the git-reflow reserved commands (use
, before
, after
, command
) are executed in the context of our Core workflow class. This gives you the ability to use any code available to GitReflow
. We encourage you to use as much of GitReflow's tooling as possible so that you can take full advantage of getting the current branch name, logging, exception-handling, colorized output, and several other features that are baked into GitReflow
's internals. For a full list of what's available, see the Available Workflow Helpers section.
-
run
, orGitReflow.run_command_with_label
– Easily run commands -
say
– output something to the STDOUT with special formatting Git-related helpers: -
git_root_dir
– The root directory of your git repository -
remote_user
– The username the repository belongs to (e.g.reenhanced
for this repo) -
remote_repo_name
– The name of the repository (e.g.gitreflow
for this repo) -
current_branch
– The currently checked out branch -
update_current_branch
– Pulls in the latest changes from remote for the current branch -
push_current_branch
– Pushes the current branch to remote -
fetch_destination(branch_name)
– Fetchesbranch_name
from remote -
update_destination(branch_name)
– Checks outbranch_name
, pulls in latest changes from remote, then re-checks-out the branch you were on -
update_feature_branch
– Pulls in any changes from remote for the current branch, then merges in any changes from remote/base_branch -
append_to_squashed_commit_message(message)
– Appendmessage
to the squashed commit message - https://github.com/reenhanced/gitreflow/blob/master/lib/git_reflow/git_helpers.rb
Also of note, GitReflow.git_server.connection
will give you access to the api for your git server. In the case of GitHub, it is the equivalent of GitHub.new