branchbot 0.1.0 → 0.2.1
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/Gemfile.lock +2 -2
- data/README.md +6 -3
- data/branchbot.gemspec +1 -1
- data/exe/branchbot +6 -3
- data/lib/branchbot/branch_switcher.rb +29 -11
- data/lib/branchbot/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d566da70cfe92c75f6d5697f591929936d2d6af2d800e876d1ae7b257c8d653e
|
4
|
+
data.tar.gz: 5880c9bcb0473c6fc9cbaf47020e3306c792cca9270fe9e6811a7412814c3ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8414dfc2e82d04ac9080411872570d1040c819b63a7ea639630de782bcea48d4f9a866f9514e80ea769130252b03fd36f01c54568422e1cd75cb7b711e459ed
|
7
|
+
data.tar.gz: d5f3d8c08a348836e48dcd18ab3f04842c79d29129591a91074b7a27b0a23b3c105b4d148d1fadde4f66998cf48fbd0a1589684b25aa4b8338816e35a670d445
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,11 @@ This allows you to make some changes to the structure of your database on a feat
|
|
16
16
|
|
17
17
|
Note: Be sure to keep the `post-checkout` name to match Git's expectations.
|
18
18
|
|
19
|
+
# Options
|
20
|
+
|
21
|
+
- `--app-root` - The app root relative to the project root (default: '.')
|
22
|
+
- `--db-config-erb` - Interpret database.yml as ERB an template before parsing as YML (default: disabled)
|
23
|
+
|
19
24
|
# Support
|
20
25
|
|
21
26
|
Only PostgreSQL and MySQL databases are currently supported.
|
@@ -24,7 +29,7 @@ Only PostgreSQL and MySQL databases are currently supported.
|
|
24
29
|
|
25
30
|
While this hook is geared towards Rails and depends on Ruby, it is very easy to use it in non-Ruby/Rails projects, so long as you have Ruby installed on your system.
|
26
31
|
|
27
|
-
This script will look for a `database.yml`
|
32
|
+
This script will look for a `config/database.yml` file in your app's root (configurable via `--app-root`), and expects it to look like this:
|
28
33
|
|
29
34
|
```yaml
|
30
35
|
development:
|
@@ -34,6 +39,4 @@ development:
|
|
34
39
|
database: <database name>
|
35
40
|
```
|
36
41
|
|
37
|
-
The path to this file is configurable via the `--db-config-path` option.
|
38
|
-
|
39
42
|
We currently support two adapters: `mysql2` and `postgresql`. We don't actually rely on these gems, but instead use them to determine which database's command line tools we should use (mysqldump/mysql or pg_dump/psql). Use `mysql2` if you are using a MySQL database, or `postgresql` if you are using a PostgreSQL database.
|
data/branchbot.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
# Uncomment to register a new dependency of your gem
|
30
30
|
spec.add_runtime_dependency "commander", '~> 4.6.0'
|
31
|
-
|
31
|
+
|
32
32
|
# For more information and examples about making a new gem, checkout our
|
33
33
|
# guide at: https://bundler.io/guides/creating_gem.html
|
34
34
|
end
|
data/exe/branchbot
CHANGED
@@ -11,7 +11,8 @@ program :description, "Saves and restores the state of your local database as yo
|
|
11
11
|
command :switch do |cmd|
|
12
12
|
cmd.syntax = "branchbot switch [options]"
|
13
13
|
cmd.option '--from FROM_REF', String, 'ref switching from'
|
14
|
-
cmd.option '--
|
14
|
+
cmd.option '--app-root relative/path/to/app', String, 'path to app root relative to project root (default: .)'
|
15
|
+
cmd.option '--db-config-erb', 'Interpret the database config as ERB before parsing YML'
|
15
16
|
|
16
17
|
cmd.action do |args, options|
|
17
18
|
unless options.from
|
@@ -19,10 +20,12 @@ command :switch do |cmd|
|
|
19
20
|
next
|
20
21
|
end
|
21
22
|
|
22
|
-
options.default
|
23
|
+
options.default app_root: '.'
|
24
|
+
options.default db_config_erb: false
|
23
25
|
|
24
26
|
Branchbot::BranchSwitcher.new(
|
25
|
-
|
27
|
+
app_root: options.app_root,
|
28
|
+
erb_in_database_yml: options.db_config_erb
|
26
29
|
).switch_from(options.from)
|
27
30
|
end
|
28
31
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Branchbot
|
2
2
|
class BranchSwitcher
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(app_root: '.', erb_in_database_yml: true)
|
4
|
+
@app_root = app_root
|
5
|
+
@project_root = %x[git rev-parse --show-toplevel].strip
|
6
|
+
@dump_folder = "#{@project_root}/.db_branch_dumps"
|
7
|
+
@erb_in_database_yml = erb_in_database_yml
|
5
8
|
end
|
6
9
|
|
7
10
|
def switch_from(prev_ref)
|
@@ -13,11 +16,8 @@ module Branchbot
|
|
13
16
|
# destination branch, so we can remove that immediately.
|
14
17
|
@source_branches = branches_from_refhead(prev_ref).reject{ |b| b == @destination_branch }
|
15
18
|
|
16
|
-
@project_root = %x[git rev-parse --show-toplevel].strip
|
17
|
-
@dump_folder = "#{@project_root}/.db_branch_dumps"
|
18
|
-
|
19
19
|
# Load Rails DB config and grab database name
|
20
|
-
@rails_db_config = YAML.load(
|
20
|
+
@rails_db_config = YAML.load(db_config_yml)
|
21
21
|
dev_database_name = @rails_db_config['development']['database']
|
22
22
|
|
23
23
|
begin
|
@@ -57,24 +57,42 @@ module Branchbot
|
|
57
57
|
`git show-ref --heads | grep #{ref} | awk '{print $2}'`.split("\n").map{ |b| b.sub(/^refs\/heads\//, '') }
|
58
58
|
end
|
59
59
|
|
60
|
+
def app_root
|
61
|
+
File.join @project_root, @app_root
|
62
|
+
end
|
63
|
+
|
60
64
|
def prepare_test_database
|
61
|
-
if File.exists?("#{
|
65
|
+
if File.exists?("#{app_root}/Rakefile")
|
62
66
|
print "Preparing test database..."
|
63
67
|
|
64
68
|
rake_cmd = "rake db:test:prepare"
|
65
69
|
|
66
|
-
if File.exists?("#{
|
70
|
+
if File.exists?("#{app_root}/bin/rake")
|
67
71
|
rake_cmd = "./bin/#{rake_cmd}"
|
68
|
-
elsif File.exists?("#{
|
72
|
+
elsif File.exists?("#{app_root}/Gemfile")
|
69
73
|
rake_cmd = "bundle exec #{rake_cmd}"
|
70
74
|
end
|
71
75
|
|
72
|
-
system rake_cmd
|
76
|
+
system "cd \"#{app_root}\" && #{rake_cmd}"
|
73
77
|
|
74
78
|
print "done!\n"
|
75
79
|
else
|
76
80
|
print "No Rakefile detected, skipping test database restoration\n"
|
77
81
|
end
|
78
82
|
end
|
83
|
+
|
84
|
+
def db_config_path
|
85
|
+
File.join app_root, 'config', 'database.yml'
|
86
|
+
end
|
87
|
+
|
88
|
+
def db_config_yml
|
89
|
+
database_yml_content = File.read(db_config_path)
|
90
|
+
|
91
|
+
if @erb_in_database_yml
|
92
|
+
ERB.new(database_yml_content).result
|
93
|
+
else
|
94
|
+
database_yml_content
|
95
|
+
end
|
96
|
+
end
|
79
97
|
end
|
80
|
-
end
|
98
|
+
end
|
data/lib/branchbot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: branchbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Ryan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.3.7
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Saves and restores the state of your local database as you work on different
|