Module: FalkorLib::GitFlow
- Defined in:
- lib/falkorlib/git/flow.rb
Overview
Management of git flow operations I'm using everywhere
Class Method Summary collapse
-
.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
. -
.init(path = Dir.pwd) ⇒ Object
Initialize a git-flow repository.
-
.init?(path = Dir.pwd) ⇒ Boolean
Check if git-flow is initialized.
-
.start(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support start
.
Class Method Details
.command(name, type = 'feature', action = 'start', path = Dir.pwd, optional_args = '') ⇒ Object
generic function to run any of the gitflow commands
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/falkorlib/git/flow.rb', line 121 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
141 142 143 |
# File 'lib/falkorlib/git/flow.rb', line 141 def finish (type, name, path = Dir.pwd, optional_args = '') command(name, type, 'finish', path, optional_args) end |
.init(path = Dir.pwd) ⇒ Object
Initialize a git-flow repository
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
# File 'lib/falkorlib/git/flow.rb', line 43 def init(path = Dir.pwd) exit_status = FalkorLib::Git.init(path) error "you shall install git-flow: see https://github.com/nvie/gitflow/wiki/Installation" unless command?('git-flow') 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 a #{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) if remotes.include?( 'origin' ) info "=> configure remote (tracked) branches" exit_status = FalkorLib::Git.fetch(path) FalkorLib.config.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 FalkorLib.config.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" FalkorLib.config.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 = FalkorLib.config.gitflow[:branches][:develop] info "Checkout to the main development branch '#{devel_branch}'" exit_status = run %{ git checkout #{devel_branch} } if branches.include?('master') && ! FalkorLib.config.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?(path = Dir.pwd) ⇒ Boolean
Check if git-flow is initialized
110 111 112 113 114 115 116 117 |
# File 'lib/falkorlib/git/flow.rb', line 110 def init?(path = Dir.pwd) res = FalkorLib::Git.init?(path) Dir.chdir(path) do gf_check = `git config --get-regexp 'gitflow*'` res &= ! gf_check.empty? end res end |
.start(type, name, path = Dir.pwd, optional_args = '') ⇒ Object
git flow hotfix, release, support start
136 137 138 |
# File 'lib/falkorlib/git/flow.rb', line 136 def start (type, name, path = Dir.pwd, optional_args = '') command(name, type, 'start', path, optional_args) end |