rails-worktree 0.1.3 → 0.1.4
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 +4 -4
- data/lib/worktree/cli.rb +14 -7
- data/lib/worktree/commands/close.rb +26 -19
- data/lib/worktree/commands/create.rb +5 -2
- data/lib/worktree/commands/init.rb +8 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c771eeca1a0ebd25d16f5b998d7c85664b29dce630232228188177c48ef406a
|
|
4
|
+
data.tar.gz: ab045a8fb0f2a5c2af5bcaacfb35237cdd3ce49c404a539f5a51cc944e7f8f82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f7974fdd4e268a473d0f7d72957e832cee8b8a40606521cbcb6ebcb4410b9faabf02a103ff632fbe5a4d86b515573a215dd7abcaf7621fae7729c9f157b2e7c
|
|
7
|
+
data.tar.gz: fb7284245d332144b3e0d4eead26e63b811459fb8afc096604f6cde6e053588261ab9a29e32e0390c079de3ab79cf5c4134a528ab37d8500bd4cdf154d38e91e
|
data/lib/worktree/cli.rb
CHANGED
|
@@ -14,18 +14,21 @@ module RailsWorktree
|
|
|
14
14
|
exit 1
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# Extract flags
|
|
18
|
+
@skip_seeds = @args.delete("--skip-seeds")
|
|
19
|
+
|
|
17
20
|
case @args[0]
|
|
18
21
|
when "--close", "close"
|
|
19
22
|
@args.shift
|
|
20
23
|
Commands::Close.new(@args).run
|
|
21
24
|
when "--init", "init"
|
|
22
25
|
@args.shift
|
|
23
|
-
Commands::Init.new(@args).run
|
|
26
|
+
Commands::Init.new(@args, skip_seeds: @skip_seeds).run
|
|
24
27
|
when "--help", "-h", "help"
|
|
25
28
|
print_usage
|
|
26
29
|
else
|
|
27
30
|
# Default: create worktree
|
|
28
|
-
Commands::Create.new(@args).run
|
|
31
|
+
Commands::Create.new(@args, skip_seeds: @skip_seeds).run
|
|
29
32
|
end
|
|
30
33
|
end
|
|
31
34
|
|
|
@@ -33,9 +36,9 @@ module RailsWorktree
|
|
|
33
36
|
|
|
34
37
|
def print_usage
|
|
35
38
|
puts <<~USAGE
|
|
36
|
-
Usage: worktree <name> [base-branch]
|
|
39
|
+
Usage: worktree <name> [base-branch] [options]
|
|
37
40
|
worktree --close [worktree-name]
|
|
38
|
-
worktree --init <worktree-name>
|
|
41
|
+
worktree --init <worktree-name> [options]
|
|
39
42
|
|
|
40
43
|
Creates a new git worktree and initializes it with configuration
|
|
41
44
|
|
|
@@ -45,14 +48,18 @@ module RailsWorktree
|
|
|
45
48
|
--init <name> Initialize a worktree (usually called automatically)
|
|
46
49
|
--help, -h Show this help message
|
|
47
50
|
|
|
51
|
+
Options:
|
|
52
|
+
--skip-seeds Skip database seeding during initialization
|
|
53
|
+
|
|
48
54
|
Arguments:
|
|
49
55
|
<name> Name of the worktree (required)
|
|
50
56
|
[base-branch] Branch to create worktree from (default: current branch)
|
|
51
57
|
|
|
52
58
|
Examples:
|
|
53
|
-
worktree feature-branch
|
|
54
|
-
worktree
|
|
55
|
-
worktree --close
|
|
59
|
+
worktree feature-branch # Create new worktree
|
|
60
|
+
worktree feature-branch --skip-seeds # Create without seeding database
|
|
61
|
+
worktree --close feature-branch # Close worktree from main repo
|
|
62
|
+
worktree --close # Close worktree from within it
|
|
56
63
|
USAGE
|
|
57
64
|
end
|
|
58
65
|
end
|
|
@@ -23,6 +23,7 @@ module RailsWorktree
|
|
|
23
23
|
puts ""
|
|
24
24
|
|
|
25
25
|
drop_databases
|
|
26
|
+
remove_node_modules
|
|
26
27
|
remove_worktree
|
|
27
28
|
prune_worktrees
|
|
28
29
|
delete_branch
|
|
@@ -30,6 +31,7 @@ module RailsWorktree
|
|
|
30
31
|
puts ""
|
|
31
32
|
puts "✓ Worktree '#{@worktree_name}' closed successfully!"
|
|
32
33
|
puts " Databases dropped: #{@dev_database_name}, #{@test_database_name}"
|
|
34
|
+
puts " node_modules removed"
|
|
33
35
|
puts " Worktree removed from #{@worktree_path}"
|
|
34
36
|
puts " Branch #{@worktree_name} deleted"
|
|
35
37
|
end
|
|
@@ -54,12 +56,16 @@ module RailsWorktree
|
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def get_db_prefix
|
|
59
|
+
# Try to get prefix from database.yml first
|
|
57
60
|
database_yml = File.join(@main_worktree, "config/database.yml")
|
|
58
|
-
|
|
61
|
+
if File.exist?(database_yml)
|
|
62
|
+
content = File.read(database_yml)
|
|
63
|
+
match = content.match(/database:\s*(\w+)_development/)
|
|
64
|
+
return match[1] if match
|
|
65
|
+
end
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
match ? match[1] : nil
|
|
67
|
+
# Fall back to using the Rails app name (directory name of main worktree)
|
|
68
|
+
File.basename(@main_worktree)
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
def detect_paths
|
|
@@ -78,24 +84,25 @@ module RailsWorktree
|
|
|
78
84
|
puts "Dropping databases..."
|
|
79
85
|
|
|
80
86
|
Dir.chdir(@worktree_dir) do
|
|
81
|
-
env_file = ".env"
|
|
82
|
-
env_content = File.exist?(env_file) ? File.read(env_file) : ""
|
|
83
|
-
|
|
84
87
|
# Drop development database
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
puts("Warning: Could not drop development database #{@dev_database_name}")
|
|
88
|
-
else
|
|
89
|
-
puts "Warning: DATABASE_NAME_DEVELOPMENT not set in .env, skipping development database drop"
|
|
90
|
-
end
|
|
88
|
+
system("RAILS_ENV=development bin/rails db:drop 2>/dev/null") ||
|
|
89
|
+
puts("Warning: Could not drop development database #{@dev_database_name}")
|
|
91
90
|
|
|
92
91
|
# Drop test database
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
system("RAILS_ENV=test bin/rails db:drop 2>/dev/null") ||
|
|
93
|
+
puts("Warning: Could not drop test database #{@test_database_name}")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def remove_node_modules
|
|
98
|
+
puts "Removing node_modules..."
|
|
99
|
+
|
|
100
|
+
node_modules_path = File.join(@worktree_dir, "node_modules")
|
|
101
|
+
if Dir.exist?(node_modules_path)
|
|
102
|
+
FileUtils.rm_rf(node_modules_path)
|
|
103
|
+
puts "node_modules removed"
|
|
104
|
+
else
|
|
105
|
+
puts "No node_modules to remove"
|
|
99
106
|
end
|
|
100
107
|
end
|
|
101
108
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
module RailsWorktree
|
|
2
2
|
module Commands
|
|
3
3
|
class Create
|
|
4
|
-
def initialize(args)
|
|
4
|
+
def initialize(args, skip_seeds: false)
|
|
5
5
|
@worktree_name = args[0]
|
|
6
6
|
@base_branch = args[1]
|
|
7
|
+
@skip_seeds = skip_seeds
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def run
|
|
@@ -29,12 +30,14 @@ module RailsWorktree
|
|
|
29
30
|
puts "Initializing worktree..."
|
|
30
31
|
|
|
31
32
|
Dir.chdir(worktree_path) do
|
|
32
|
-
Init.new([@worktree_name]).run
|
|
33
|
+
Init.new([@worktree_name], skip_seeds: @skip_seeds).run
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
puts ""
|
|
36
37
|
puts "To switch to the new worktree:"
|
|
37
38
|
puts " cd #{absolute_path}"
|
|
39
|
+
puts ""
|
|
40
|
+
puts "To start the development server: bin/dev"
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
private
|
|
@@ -3,8 +3,9 @@ require "fileutils"
|
|
|
3
3
|
module RailsWorktree
|
|
4
4
|
module Commands
|
|
5
5
|
class Init
|
|
6
|
-
def initialize(args)
|
|
6
|
+
def initialize(args, skip_seeds: false)
|
|
7
7
|
@worktree_name = args[0]
|
|
8
|
+
@skip_seeds = skip_seeds
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def run
|
|
@@ -35,8 +36,6 @@ module RailsWorktree
|
|
|
35
36
|
puts " Development database: #{@dev_database_name}"
|
|
36
37
|
puts " Test database: #{@test_database_name}"
|
|
37
38
|
puts " Configuration files copied"
|
|
38
|
-
puts ""
|
|
39
|
-
puts "To start the development server: bin/dev"
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
private
|
|
@@ -156,8 +155,12 @@ module RailsWorktree
|
|
|
156
155
|
system("RAILS_ENV=development bin/rails db:migrate") || puts("Warning: Could not run migrations")
|
|
157
156
|
system("RAILS_ENV=test bin/rails db:migrate") || puts("Warning: Could not run test migrations")
|
|
158
157
|
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
unless @skip_seeds
|
|
159
|
+
puts "Seeding development database..."
|
|
160
|
+
system("RAILS_ENV=development bin/rails db:seed > /dev/null 2>&1") || puts("Warning: Could not seed database")
|
|
161
|
+
else
|
|
162
|
+
puts "Skipping database seeding..."
|
|
163
|
+
end
|
|
161
164
|
end
|
|
162
165
|
end
|
|
163
166
|
end
|