Module: FalkorLib::GitFlow
- Defined in:
- lib/falkorlib/git/flow.rb
Overview
Management of [git flow](github.com/nvie/gitflow) operations I’m using everywhere
Class Method Summary collapse
-
.branches(type = :master, dir = Dir.pwd, options = {}) ⇒ Object
Return the Gitflow branch :master: Master Branch name for production releases :develop:.
-
.command(name, type = 'feature', action = 'start', path = Dir.pwd, optional_args = '') ⇒ Object
generic function to run any of the gitflow commands.
-
.finish(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support finish <name>.
-
.init(path = Dir.pwd, options = {}) ⇒ Object
Initialize a git-flow repository Supported options: :interactive [boolean] confirm Gitflow branch names :master [string] Branch name for production releases :develop [string] Branch name for development commits.
-
.init?(dir = Dir.pwd) ⇒ Boolean
init? ###### Check if gitflow has been initialized.
-
.start(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support start <name>.
Class Method Details
.branches(type = :master, dir = Dir.pwd, options = {}) ⇒ Object
Return the Gitflow branch :master: Master Branch name for production releases :develop:
185 186 187 188 |
# File 'lib/falkorlib/git/flow.rb', line 185 def branches(type = :master, dir = Dir.pwd, = {}) FalkorLib::Git.config("gitflow.branch.#{type}", dir) #confs[type.to_sym] end |
.command(name, type = 'feature', action = 'start', path = Dir.pwd, optional_args = '') ⇒ Object
generic function to run any of the gitflow commands
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/falkorlib/git/flow.rb', line 156 def command(name, type = 'feature', action = 'start', path = Dir.pwd, optional_args = '') error "Invalid git-flow type '#{type}'" unless ['feature', 'release', 'hotfix', 'support'].include?(type) error "Invalid action '#{action}'" unless ['start', 'finish'].include?(action) error "You must provide a name" if name == '' error "The name '#{name}' cannot contain spaces" if name =~ /\s+/ exit_status = 1 Dir.chdir( FalkorLib::Git.rootdir(path) ) do exit_status = run %{ git flow #{type} #{action} #{optional_args} #{name} } end exit_status end |
.finish(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support finish <name>
176 177 178 |
# File 'lib/falkorlib/git/flow.rb', line 176 def finish (type, name, path = Dir.pwd, optional_args = '') command(name, type, 'finish', path, optional_args) end |
.init(path = Dir.pwd, options = {}) ⇒ Object
Initialize a git-flow repository Supported options: :interactive [boolean] confirm Gitflow branch names :master [string] Branch name for production releases :develop [string] Branch name for development commits
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/falkorlib/git/flow.rb', line 69 def init(path = Dir.pwd, = {}) exit_status = FalkorLib::Git.init(path, ) unless command?('git-flow') # Check (mainly for Linux) if the command is not available under `/usr/lib/git-core` git_lib = '/usr/lib/git-core/' error "you shall install git-flow: see https://github.com/nvie/gitflow/wiki/Installation" unless File.exist?(File.join(git_lib, 'git-flow')) end remotes = FalkorLib::Git.remotes(path) git_root_dir = FalkorLib::Git.rootdir( path ) Dir.chdir( git_root_dir ) do unless FalkorLib::Git.has_commits?( git_root_dir) warn "Not yet any commit detected in this repository." readme = 'README.md' unless File.exists?( readme ) answer = ask(cyan("=> initialize a commit with an [empty] #{readme} file (Y|n)?"), 'Yes') exit 0 if answer =~ /n.*/i FileUtils.touch(readme) end FalkorLib::Git.add(readme, "Initiate the repository with a '#{readme}' file") end branches = FalkorLib::Git.list_branch(path) gitflow_branches = FalkorLib.config.gitflow[:branches].clone # correct eventually the considered branch from the options gitflow_branches.each do |t,b| gitflow_branches[t] = [t.to_sym] if [t.to_sym] confs = FalkorLib::Git.config('gitflow*', path, :hash => true) unless confs.empty? gitflow_branches[t] = confs["gitflow.branch.#{t}"] end end if [:interactive] gitflow_branches[:master] = ask("=> branch name for production releases", gitflow_branches[:master]) gitflow_branches[:develop] = ask("=> branch name for development commits", gitflow_branches[:develop]) end ap gitflow_branches if [:debug] if remotes.include?( 'origin' ) info "=> configure remote (tracked) branches" exit_status = FalkorLib::Git.fetch(path) gitflow_branches.each do |type,branch| if branches.include? "remotes/origin/#{branch}" exit_status = FalkorLib::Git.grab(branch, path) else unless branches.include? branch info "=> creating the branch '#{branch}'" FalkorLib::Git.create_branch( branch, path ) end exit_status = FalkorLib::Git.publish(branch, path ) end end else gitflow_branches.each do |type, branch| unless branches.include? branch info " => creating the branch '#{branch}'" exit_status = FalkorLib::Git.create_branch( branch, path ) end end end #info "initialize git flow configs" gitflow_branches.each do |t,branch| exit_status = execute "git config gitflow.branch.#{t} #{branch}" end FalkorLib.config.gitflow[:prefix].each do |t,prefix| exit_status = execute "git config gitflow.prefix.#{t} #{prefix}" end devel_branch = gitflow_branches[:develop] #info "checkout to the main development branch '#{devel_branch}'" exit_status = run %{ git checkout #{devel_branch} } # git config branch.$(git rev-parse --abbrev-ref HEAD).mergeoptions --no-edit for the develop branch exit_status = execute "git config branch.#{devel_branch}.mergeoptions --no-edit" if branches.include?('master') && ! gitflow_branches.values.include?( 'master' ) warn "Your git-flow confuguration does not hold the 'master' branch any more" warn "You probably want to get rid of it asap by running 'git branch -d master'" end if devel_branch != 'master' && remotes.include?( 'origin' ) && branches.include?( 'remotes/origin/master') warn "You might want to change the remote default branch to point to '#{devel_branch}" puts "=> On github: Settings > Default Branch > #{devel_branch}" puts "=> On the remote bare Git repository: 'git symbolic-ref HEAD refs/head/#{devel_branch}'" end end exit_status end |
.init?(dir = Dir.pwd) ⇒ Boolean
init? ###### Check if gitflow has been initialized
56 57 58 59 60 61 62 |
# File 'lib/falkorlib/git/flow.rb', line 56 def init?(dir = Dir.pwd) res = FalkorLib::Git.init?(dir) if res res &= !FalkorLib::Git.config('gitflow*', dir).empty? end res end |
.start(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support start <name>
171 172 173 |
# File 'lib/falkorlib/git/flow.rb', line 171 def start (type, name, path = Dir.pwd, optional_args = '') command(name, type, 'start', path, optional_args) end |