Class: Bonchi::CLI
Class Method Summary collapse
Instance Method Summary collapse
- #create(branch, base = nil) ⇒ Object
- #init ⇒ Object
- #list ⇒ Object
- #pr(input) ⇒ Object
- #prune ⇒ Object
- #remove(branch) ⇒ Object
- #rmf(branch) ⇒ Object
- #rmrf(branch) ⇒ Object
- #setup(*args) ⇒ Object
- #shellenv ⇒ Object
- #switch(branch) ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
7 8 9 |
# File 'lib/bonchi/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#create(branch, base = nil) ⇒ Object
68 69 70 |
# File 'lib/bonchi/cli.rb', line 68 def create(branch, base = nil) invoke :switch, [branch], c: true, base: base, setup: [:setup], upto: [:upto] end |
#init ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/bonchi/cli.rb', line 117 def init path = File.join(Dir.pwd, ".worktree.yml") if File.exist?(path) abort "Error: .worktree.yml already exists" end File.write(path, WORKTREE_YML_TEMPLATE) puts "Created #{path}" end |
#list ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/bonchi/cli.rb', line 140 def list lines = Git.worktree_list base = Git.default_base_branch home = Dir.home lines.each do |line| branch = line[/\[([^\]]+)\]/, 1] path = line.split(/\s+/).first line = line.sub(home, "~") unless branch puts line next end if branch == base puts line next end merged = Git.merged?(branch, into: base) clean = Git.clean?(path) = [] << "#{color(:yellow)}dirty#{reset}" unless clean << "#{color(:green)}merged#{reset}" if merged if .any? puts "#{line} #{.join(" ")}" else puts line end end end |
#pr(input) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bonchi/cli.rb', line 86 def pr(input) pr_number = extract_pr_number(input) branch = "pr-#{pr_number}" path = Git.worktree_dir(branch) existing = Git.worktree_path_for(branch) if existing puts "Worktree already exists: #{existing}" signal_cd(existing) return end Git.fetch_pr(pr_number) Git.worktree_add(path, branch) Git.set_pr_upstream(pr_number) puts "PR ##{pr_number} checked out at: #{path}" signal_cd(path) if [:setup] && Config.from_main_worktree puts "" Setup.new(worktree: path).run(upto: [:upto]) end end |
#prune ⇒ Object
207 208 209 210 |
# File 'lib/bonchi/cli.rb', line 207 def prune Git.worktree_prune puts "Pruned stale worktree administrative files" end |
#remove(branch) ⇒ Object
185 186 187 |
# File 'lib/bonchi/cli.rb', line 185 def remove(branch) remove_worktree(branch, force: [:force], delete_branch: :merged) end |
#rmf(branch) ⇒ Object
190 191 192 |
# File 'lib/bonchi/cli.rb', line 190 def rmf(branch) remove_worktree(branch, force: true, delete_branch: :merged) end |
#rmrf(branch) ⇒ Object
195 196 197 |
# File 'lib/bonchi/cli.rb', line 195 def rmrf(branch) remove_worktree(branch, force: true, delete_branch: :always) end |
#setup(*args) ⇒ Object
129 130 131 |
# File 'lib/bonchi/cli.rb', line 129 def setup(*args) Setup.new.run(args, upto: [:upto]) end |
#shellenv ⇒ Object
213 214 215 |
# File 'lib/bonchi/cli.rb', line 213 def shellenv puts SHELL_ENV end |
#switch(branch) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bonchi/cli.rb', line 35 def switch(branch) abort "Error: --base requires -c flag" if [:base] && ![:c] existing = Git.worktree_path_for(branch) if existing puts "Worktree already exists: #{existing}" signal_cd(existing) return end path = Git.worktree_dir(branch) if [:c] && !Git.branch_exists?(branch) base = [:base] || Git.default_base_branch Git.worktree_add_new_branch(path, branch, base) elsif [:c] || Git.branch_exists?(branch) Git.worktree_add(path, branch) else abort "Error: Branch '#{branch}' does not exist\nUse 'bonchi switch -c #{branch}' to create a new branch" end puts "Worktree created at: #{path}" signal_cd(path) if [:setup] && Config.from_main_worktree puts "" Setup.new(worktree: path).run(upto: [:upto]) end end |
#version ⇒ Object
12 13 14 |
# File 'lib/bonchi/cli.rb', line 12 def version puts "bonchi #{VERSION}" end |