bonchi 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 137e1eebb563dfaf05a9e6928abeb3832ff8e6231f7e1b4ea176037b605b2489
4
- data.tar.gz: 8f22938f47fbc5068cb0a40a02fd31c875b5cdc5b7e699b6049752060ec3accb
3
+ metadata.gz: d0506e896860d23e52035729f193224f9a1d2a54799b2f7deb73691ddde7ba61
4
+ data.tar.gz: 831b6a75a71e40d6ccb7d09c8db83aafff0a56ea301d6083649b440245cfb3c6
5
5
  SHA512:
6
- metadata.gz: 47d60879e7c32a8e518c3719d78c6c952dcc850c9897f49e4da0b4370d3a3e07e2d1233cf4b15a8eaf257671eae02aad4fd7d89d40d5a86525b8bf6a3ab6157b
7
- data.tar.gz: f6a8c72b294fd4c6e29dff35d20c085463e0411bab413971c934ca43b80b331caa095b726d1cace6305a9db20865a6ec3877de1cdaf89d9d98f3aa9bbef2b284
6
+ metadata.gz: 7e483c14fee4002b3cbcb0816a4cd351b190ff50a7e01e0db48606e749df21a954d71ea79c8ad7ae982807f90618f44f6461fbd26ad7814196c1c22c53c51bd0
7
+ data.tar.gz: 178967a54213235cd13552fb36283a12ccb4ea669533df6abad0a0049fb3063cc7d6332e9e076e7c6cb407650628d597eb884bd3e5827a11cecc355eef3bda80
data/lib/bonchi/cli.rb CHANGED
@@ -127,16 +127,18 @@ module Bonchi
127
127
  desc "remove BRANCH", "Remove a worktree"
128
128
  long_desc <<~DESC
129
129
  Remove a worktree and its directory. Refuses to remove worktrees
130
- with uncommitted changes or untracked files (use `git worktree remove --force` to override).
130
+ with uncommitted changes or untracked files unless --force is used.
131
131
 
132
132
  Aliases: rm
133
133
  DESC
134
+ option :force, type: :boolean, default: false, desc: "Force removal even with uncommitted changes"
134
135
  def remove(branch)
135
136
  path = Git.worktree_path_for(branch)
136
137
  abort "Error: No worktree found for branch: #{branch}" unless path
137
138
 
138
- Git.worktree_remove(path)
139
+ Git.worktree_remove(path, force: options[:force])
139
140
  puts "Removed worktree: #{path}"
141
+ signal_cd(Git.main_worktree)
140
142
  end
141
143
 
142
144
  desc "prune", "Prune stale worktree admin files"
@@ -191,6 +193,10 @@ module Bonchi
191
193
  # copy:
192
194
  # - .env.local
193
195
 
196
+ # Files to symlink from the main worktree (useful for large directories).
197
+ # link:
198
+ # - node_modules
199
+
194
200
  # Env var names to allocate unique ports for (from global pool).
195
201
  # ports:
196
202
  # - PORT
data/lib/bonchi/config.rb CHANGED
@@ -4,9 +4,9 @@ module Bonchi
4
4
  class Config
5
5
  include Colors
6
6
 
7
- KNOWN_KEYS = %w[copy ports replace pre_setup setup].freeze
7
+ KNOWN_KEYS = %w[copy link ports replace pre_setup setup].freeze
8
8
 
9
- attr_reader :copy, :ports, :replace, :pre_setup, :setup
9
+ attr_reader :copy, :link, :ports, :replace, :pre_setup, :setup
10
10
 
11
11
  def initialize(path)
12
12
  data = YAML.load_file(path)
@@ -15,6 +15,7 @@ module Bonchi
15
15
  unknown.each { |k| warn "#{color(:yellow)}Warning:#{reset} unknown key '#{k}' in .worktree.yml, ignoring" }
16
16
 
17
17
  @copy = Array(data["copy"])
18
+ @link = Array(data["link"])
18
19
  @ports = Array(data["ports"])
19
20
  @replace = data["replace"] || {}
20
21
  @pre_setup = Array(data["pre_setup"])
@@ -24,8 +25,11 @@ module Bonchi
24
25
  end
25
26
 
26
27
  def self.from_main_worktree
27
- main = Git.main_worktree
28
- path = File.join(main, ".worktree.yml")
28
+ from_worktree(Git.main_worktree)
29
+ end
30
+
31
+ def self.from_worktree(dir)
32
+ path = File.join(dir, ".worktree.yml")
29
33
  return nil unless File.exist?(path)
30
34
 
31
35
  new(path)
data/lib/bonchi/git.rb CHANGED
@@ -50,8 +50,11 @@ module Bonchi
50
50
  system("git", "worktree", "add", path, "-b", branch, base) || abort("Failed to add worktree")
51
51
  end
52
52
 
53
- def worktree_remove(path)
54
- system("git", "worktree", "remove", path) || abort("Failed to remove worktree")
53
+ def worktree_remove(path, force: false)
54
+ cmd = ["git", "worktree", "remove"]
55
+ cmd << "--force" if force
56
+ cmd << path
57
+ system(*cmd) || abort("Failed to remove worktree")
55
58
  end
56
59
 
57
60
  def worktree_prune
data/lib/bonchi/setup.rb CHANGED
@@ -26,8 +26,17 @@ module Bonchi
26
26
 
27
27
  puts "Setting up worktree from: #{@main_worktree}"
28
28
 
29
- allocate_ports(config.ports) if config.ports.any?
30
29
  copy_files(config.copy)
30
+ link_files(config.link)
31
+
32
+ # Prefer linked worktree's .worktree.yml if it was copied or already exists
33
+ linked_config = Config.from_worktree(@worktree)
34
+ if linked_config
35
+ puts "Using .worktree.yml from linked worktree"
36
+ config = linked_config
37
+ end
38
+
39
+ allocate_ports(config.ports) if config.ports.any?
31
40
  replace_in_files(config.replace) if config.replace.any?
32
41
  run_pre_setup(config.pre_setup)
33
42
  exec_setup(config.setup, args)
@@ -41,11 +50,30 @@ module Bonchi
41
50
  ports.each { |name, port| ENV[name] = port.to_s }
42
51
  end
43
52
 
53
+ def link_files(files)
54
+ files.each do |file|
55
+ src = File.join(@main_worktree, file)
56
+ dest = File.join(@worktree, file)
57
+
58
+ unless File.exist?(src)
59
+ puts "#{color(:yellow)}Warning:#{reset} #{file} not found in main worktree, skipping"
60
+ next
61
+ end
62
+
63
+ FileUtils.mkdir_p(File.dirname(dest))
64
+ FileUtils.rm_rf(dest) if File.exist?(dest) || File.symlink?(dest)
65
+ FileUtils.ln_s(src, dest)
66
+ puts "Linked #{file} -> #{src}"
67
+ end
68
+ end
69
+
44
70
  def copy_files(files)
45
71
  files.each do |file|
46
72
  src = File.join(@main_worktree, file)
73
+ dest = File.join(@worktree, file)
47
74
  if File.exist?(src)
48
- FileUtils.cp(src, File.join(@worktree, file))
75
+ FileUtils.mkdir_p(File.dirname(dest))
76
+ FileUtils.cp(src, dest)
49
77
  puts "Copied #{file}"
50
78
  else
51
79
  puts "#{color(:yellow)}Warning:#{reset} #{file} not found in main worktree, skipping"
@@ -1,3 +1,3 @@
1
1
  module Bonchi
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bonchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet