worktree 0.2.2 → 0.3.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 +4 -4
- data/bin/worktree +3 -0
- data/lib/worktree/cli.rb +39 -15
- data/lib/worktree/command/add.rb +18 -36
- data/lib/worktree/command/check_stale.rb +33 -0
- data/lib/worktree/command/cherry_pick.rb +17 -33
- data/lib/worktree/command/init.rb +10 -33
- data/lib/worktree/command/open.rb +4 -12
- data/lib/worktree/command/remove.rb +16 -23
- data/lib/worktree/command/remove_stale.rb +8 -3
- data/lib/worktree/db_manager.rb +14 -6
- data/lib/worktree/feature/clone_dbs.rb +1 -2
- data/lib/worktree/launcher.rb +5 -13
- data/lib/worktree/project.rb +3 -3
- data/lib/worktree/version.rb +1 -1
- data/lib/worktree.rb +1 -1
- metadata +8 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b20449f6464b20c3bd03ca27b1a261b68ab5fe4f8bf18d52e33a95e90e60f73
|
4
|
+
data.tar.gz: 496f6c0380665811b23d80acb6adb7ae2acf84058d7cdb9a97091137cf681f06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27836a4299f8f6ffead0725a28cb7754b2a90159e65c0972ebd93b4c4d7f59b61e1a99be9e60226e5945e2be2f417f6dcf684e75cbe813fd0e97d88f073d07f4
|
7
|
+
data.tar.gz: 27d6e562eb633ba96d871f89abfeca68bcd0841d1b93ebcdb10c8569a0777b2837a78f3a0f95b6b7353d3412b0c699cb32cb727005ab1dd091c8b6f2898ae486
|
data/bin/worktree
CHANGED
data/lib/worktree/cli.rb
CHANGED
@@ -4,51 +4,71 @@ require 'worktree'
|
|
4
4
|
require 'thor'
|
5
5
|
|
6
6
|
module Worktree
|
7
|
-
class CLI < Thor
|
7
|
+
class CLI < Thor # :nodoc:
|
8
8
|
def self.exit_on_failure?
|
9
9
|
true
|
10
10
|
end
|
11
11
|
|
12
12
|
desc 'new BRANCH', 'Create a new branch'
|
13
|
-
option :from, default:
|
13
|
+
option :from, default: 'upstream/master'
|
14
14
|
option :project_dir
|
15
|
+
option :launcher_vars, type: :hash, default: {}
|
16
|
+
option :clone_db, type: :boolean, default: false
|
17
|
+
option :fetch_remote, type: :boolean, default: true
|
15
18
|
def new(branch)
|
16
19
|
Worktree::Command::Add.new(branch,
|
17
20
|
from: options[:from],
|
18
|
-
project_dir: options[:project_dir]
|
21
|
+
project_dir: options[:project_dir],
|
22
|
+
clone_db: options[:clone_db],
|
23
|
+
fetch_remote: options[:fetch_remote],
|
24
|
+
launcher_vars: options[:launcher_vars]).do!
|
19
25
|
end
|
20
26
|
|
21
27
|
desc 'open BRANCH', 'Open existing worktree'
|
22
28
|
option :project_dir
|
29
|
+
option :launcher_vars, type: :hash, default: {}
|
23
30
|
def open(branch)
|
24
31
|
Worktree::Command::Open.new(branch,
|
25
|
-
project_dir: options[:project_dir]
|
32
|
+
project_dir: options[:project_dir],
|
33
|
+
launcher_vars: options[:launcher_vars]).do!
|
26
34
|
end
|
27
35
|
|
28
|
-
desc 'remove BRANCH', 'Remove
|
36
|
+
desc 'remove BRANCH', 'Remove branch'
|
29
37
|
option :project_dir
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
option :drop_db, type: :boolean, default: false
|
39
|
+
option :drop_remote_branch, type: :boolean, default: false
|
40
|
+
option :check_merged, type: :boolean, default: false
|
41
|
+
def remove(branch)
|
42
|
+
Worktree::Command::Remove.new(branch,
|
43
|
+
project_dir: options[:project_dir],
|
44
|
+
drop_db: options[:drop_db],
|
45
|
+
drop_remote_branch: options[:drop_remote_branch],
|
46
|
+
check_merged: options[:check_merged]).do!
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'check-stale', 'Check stale branches'
|
50
|
+
option :project_dir
|
51
|
+
def check_stale
|
52
|
+
Worktree::Command::CheckStale.new(project_dir: options[:project_dir]).do!
|
35
53
|
end
|
36
54
|
|
37
55
|
desc 'remove-stale', 'Remove all stale branches'
|
38
56
|
option :project_dir
|
39
57
|
def remove_stale
|
40
58
|
Worktree::Command::RemoveStale.new(project_dir: options[:project_dir]).do!
|
41
|
-
rescue TTY::Reader::InputInterrupt
|
42
|
-
Worktree.logger.info { "You've interrupted removing of stale branches!" }
|
43
59
|
end
|
44
60
|
|
45
61
|
desc 'cherry_pick COMMIT', 'Create a new cherry pick'
|
46
62
|
option :to, required: true
|
47
63
|
option :project_dir, default: Dir.pwd
|
64
|
+
option :launcher_vars, type: :hash, default: {}
|
65
|
+
option :clone_db, type: :boolean, default: false
|
48
66
|
def cherry_pick(commit)
|
49
67
|
Worktree::Command::CherryPick.new(commit,
|
50
68
|
to: options[:to],
|
51
|
-
project_dir: options[:project_dir]
|
69
|
+
project_dir: options[:project_dir],
|
70
|
+
clone_db: options[:clone_db],
|
71
|
+
launcher_vars: options[:launcher_vars]).do!
|
52
72
|
end
|
53
73
|
|
54
74
|
desc 'configure', 'Configure worktree'
|
@@ -57,10 +77,14 @@ module Worktree
|
|
57
77
|
end
|
58
78
|
|
59
79
|
desc 'init URI', 'Initialize new worktree'
|
60
|
-
option :
|
80
|
+
option :path, default: Dir.pwd
|
81
|
+
option :remote, default: 'origin'
|
82
|
+
option :name
|
61
83
|
def init(uri)
|
62
84
|
Worktree::Command::Init.new(uri,
|
63
|
-
|
85
|
+
path: options[:path],
|
86
|
+
name: options[:name],
|
87
|
+
remote: options[:remote]).do!
|
64
88
|
end
|
65
89
|
end
|
66
90
|
end
|
data/lib/worktree/command/add.rb
CHANGED
@@ -1,56 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'tty-prompt'
|
4
|
-
|
5
3
|
module Worktree
|
6
4
|
module Command
|
7
|
-
class Add
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(branch, from:, project_dir:)
|
5
|
+
class Add # :nodoc:
|
6
|
+
def initialize(branch, from:, project_dir:, launcher_vars: {}, clone_db: false, fetch_remote: true)
|
11
7
|
@branch = branch
|
12
|
-
@
|
8
|
+
@from = from
|
13
9
|
@project_dir = File.expand_path project_dir || Project.resolve(branch).root
|
14
|
-
@
|
10
|
+
@launcher_vars = launcher_vars
|
11
|
+
@clone_db = clone_db
|
12
|
+
@fetch_remote = fetch_remote
|
15
13
|
end
|
16
14
|
|
17
15
|
def do!
|
18
|
-
|
19
|
-
|
16
|
+
# fetch git remote if allowed
|
17
|
+
git.fetch(remote, prune: true) if @fetch_remote
|
20
18
|
|
21
|
-
#
|
22
|
-
|
23
|
-
git.remotes.each { |remote| git.fetch(remote, prune: true) }
|
19
|
+
# create new git worktree
|
20
|
+
Worktree.run_command "git worktree add -b #{@branch} ../#{@branch} #{@from}", chdir: git.dir
|
24
21
|
|
25
|
-
#
|
26
|
-
|
22
|
+
# copy files specified in configuration into new folder
|
23
|
+
Feature::CopyFiles.new(project_dir: @project_dir, branch: @branch).run!
|
27
24
|
|
28
|
-
|
25
|
+
# clone PG database
|
26
|
+
Feature::CloneDbs.new(project_dir: @project_dir, branch: @branch).run! if @clone_db
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
Launcher.new(
|
33
|
-
project_dir: @project_dir,
|
34
|
-
branch: @branch
|
35
|
-
).launch!
|
28
|
+
# launch in editor
|
29
|
+
Launcher.new(project_dir: @project_dir, branch: @branch, extra_vars: @launcher_vars).launch!
|
36
30
|
end
|
37
31
|
|
38
32
|
private
|
39
33
|
|
40
|
-
def
|
41
|
-
|
42
|
-
project_dir: @project_dir,
|
43
|
-
branch: @branch
|
44
|
-
).run!
|
45
|
-
end
|
46
|
-
|
47
|
-
def clone_dbs
|
48
|
-
if File.exist?("#{@project_dir}/#{@branch}/config/database.yml")
|
49
|
-
Feature::CloneDbs.new(
|
50
|
-
project_dir: @project_dir,
|
51
|
-
branch: @branch
|
52
|
-
).run! unless TTY::Prompt.new.no?('Clone development database?')
|
53
|
-
end
|
34
|
+
def remote
|
35
|
+
@from.split('/')[0]
|
54
36
|
end
|
55
37
|
|
56
38
|
def git
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Worktree
|
4
|
+
module Command
|
5
|
+
class CheckStale
|
6
|
+
def initialize(project_dir:)
|
7
|
+
@project_dir = File.expand_path project_dir || Dir.pwd
|
8
|
+
end
|
9
|
+
|
10
|
+
def do!
|
11
|
+
# update refs
|
12
|
+
git.remotes.each { |remote| git.fetch(remote, prune: true) }
|
13
|
+
git.pull('upstream', 'master')
|
14
|
+
|
15
|
+
branches = Dir.entries(@project_dir).
|
16
|
+
select { |f| File.directory?("#{@project_dir}/#{f}}") }.
|
17
|
+
reject { |f| ['master', '.', '..'].include?(f) }
|
18
|
+
|
19
|
+
stale_branches = branches.select do |branch|
|
20
|
+
git.branch('master').contains?(branch)
|
21
|
+
end
|
22
|
+
|
23
|
+
Worktree.logger.info { "You have #{stale_branches.size} stale branches!" }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def git
|
29
|
+
@git ||= Worktree.git_for(@project_dir)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,27 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'git'
|
4
|
-
require 'tty-prompt'
|
5
|
-
|
6
3
|
module Worktree
|
7
4
|
module Command
|
8
5
|
class CherryPick
|
9
|
-
def initialize(commit, to:, project_dir:)
|
6
|
+
def initialize(commit, to:, project_dir:, launcher_vars: {}, clone_db: false)
|
10
7
|
@commit = commit[0..7] # short commit
|
11
|
-
@
|
12
|
-
@branch = "cherry-pick-#{@commit}-to-#{@
|
8
|
+
@to = to
|
9
|
+
@branch = "cherry-pick-#{@commit}-to-#{@to.tr('/', '-')}"
|
13
10
|
@project_dir = File.expand_path project_dir
|
11
|
+
@clone_db = clone_db
|
12
|
+
@launcher_vars = launcher_vars
|
14
13
|
end
|
15
14
|
|
16
15
|
def do!
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# fetch all
|
21
|
-
git.remotes.each(&:fetch)
|
16
|
+
# fetch all remotes
|
17
|
+
git.remotes.each { |remote| git.fetch(remote, prune: true) }
|
22
18
|
|
23
|
-
|
19
|
+
# create new git worktree
|
20
|
+
Worktree.run_command "git worktree add -b #{@branch} ../#{@branch} #{@to}", chdir: git.dir
|
24
21
|
|
22
|
+
# cherry-pick specified commit into specified branch
|
25
23
|
begin
|
26
24
|
Worktree.run_command "git cherry-pick #{@commit} -m 1", chdir: "#{@project_dir}/#{@branch}"
|
27
25
|
rescue Worktree::Error => e
|
@@ -29,31 +27,17 @@ module Worktree
|
|
29
27
|
Worktree.logger.warn { e.message }
|
30
28
|
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
Launcher.new(
|
35
|
-
project_dir: @project_dir,
|
36
|
-
branch: @branch
|
37
|
-
).launch!
|
38
|
-
end
|
30
|
+
# copy files specified in configuration into new folder
|
31
|
+
Feature::CopyFiles.new(project_dir: @project_dir, branch: @branch).run!
|
39
32
|
|
40
|
-
|
33
|
+
# clone PG database
|
34
|
+
Feature::CloneDbs.new(project_dir: @project_dir, branch: @branch).run! if @clone_db
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
project_dir: @project_dir,
|
45
|
-
branch: @branch
|
46
|
-
).run!
|
36
|
+
# launch in editor
|
37
|
+
Launcher.new(project_dir: @project_dir, branch: @branch, extra_vars: @launcher_vars).launch!
|
47
38
|
end
|
48
39
|
|
49
|
-
|
50
|
-
if File.exist?("#{@project_dir}/#{@branch}/config/database.yml")
|
51
|
-
Feature::CloneDbs.new(
|
52
|
-
project_dir: @project_dir,
|
53
|
-
branch: @branch
|
54
|
-
).run! unless TTY::Prompt.new.no?('Clone development database?')
|
55
|
-
end
|
56
|
-
end
|
40
|
+
private
|
57
41
|
|
58
42
|
def git
|
59
43
|
@git ||= Worktree.git_for(@project_dir)
|
@@ -1,50 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'tty-prompt'
|
4
|
-
|
5
3
|
module Worktree
|
6
4
|
module Command
|
7
|
-
class Init
|
8
|
-
def initialize(uri,
|
5
|
+
class Init # :nodoc:
|
6
|
+
def initialize(uri, name:, path:, remote: 'origin')
|
9
7
|
@uri = uri
|
10
|
-
@
|
8
|
+
@path = File.expand_path path
|
9
|
+
@remote = remote
|
10
|
+
@name = name || build_name
|
11
11
|
end
|
12
12
|
|
13
13
|
def do!
|
14
|
-
#
|
15
|
-
@git = Git.clone(@uri, tmp_repo_name, path: @repo_path)
|
16
|
-
|
17
|
-
# rearrange repo folders
|
18
|
-
FileUtils.mkdir_p "#{@repo_path}/#{repo_name}"
|
19
|
-
git_master_path = "#{@repo_path}/#{repo_name}/master"
|
20
|
-
FileUtils.mv "#{@repo_path}/#{tmp_repo_name}", git_master_path
|
21
|
-
|
22
|
-
# reinit git from new path
|
23
|
-
@git = Worktree.git_for(git_master_path)
|
24
|
-
|
25
|
-
remote_name = TTY::Prompt.new.ask?('What is remote name?', default: 'origin')
|
14
|
+
FileUtils.mkdir_p "#{@path}/#{@name}"
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
@git.add_remote remote_name, @uri
|
30
|
-
|
31
|
-
# TODO: remove origin remote?
|
16
|
+
Dir.chdir "#{@path}/#{@name}" do
|
17
|
+
@git = Git.clone(@uri, 'master', remote: @remote, log: Worktree.logger)
|
32
18
|
end
|
33
19
|
end
|
34
20
|
|
35
21
|
private
|
36
22
|
|
37
|
-
|
38
|
-
|
39
|
-
repo_name * 2
|
40
|
-
end
|
41
|
-
|
42
|
-
def repo_name
|
43
|
-
@repo_name ||= begin
|
44
|
-
u = URI(@uri)
|
45
|
-
n = u.path.split('/')
|
46
|
-
n.last[0..-5] # remove .git
|
47
|
-
end
|
23
|
+
def build_name
|
24
|
+
URI(@uri).path.split('/').last[0..-5] # remove .git
|
48
25
|
end
|
49
26
|
end
|
50
27
|
end
|
@@ -1,24 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'tty-prompt'
|
4
|
-
|
5
3
|
module Worktree
|
6
4
|
module Command
|
7
|
-
class Open
|
8
|
-
def initialize(branch, project_dir:)
|
5
|
+
class Open # :nodoc:
|
6
|
+
def initialize(branch, project_dir:, launcher_vars: {})
|
9
7
|
@branch = branch
|
10
8
|
@project_dir = File.expand_path project_dir || Project.resolve(branch).root
|
11
|
-
@
|
9
|
+
@launcher_vars = launcher_vars
|
12
10
|
end
|
13
11
|
|
14
12
|
def do!
|
15
|
-
|
16
|
-
raise 'No master repo found!' unless Dir.exist?("#{@project_dir}/master/.git")
|
17
|
-
|
18
|
-
Launcher.new(
|
19
|
-
project_dir: @project_dir,
|
20
|
-
branch: @branch
|
21
|
-
).launch!
|
13
|
+
Launcher.new(project_dir: @project_dir, branch: @branch, extra_vars: @launcher_vars).launch!
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
@@ -3,41 +3,35 @@
|
|
3
3
|
module Worktree
|
4
4
|
module Command
|
5
5
|
class Remove
|
6
|
-
|
6
|
+
NotMergedError = Class.new(StandardError)
|
7
|
+
|
8
|
+
def initialize(branch, project_dir: nil, drop_db: false, drop_remote_branch: false, check_merged: false)
|
7
9
|
@branch = branch
|
8
10
|
@project_dir = File.expand_path project_dir || Project.resolve(branch).root
|
9
|
-
@
|
10
|
-
@
|
11
|
+
@drop_db = drop_db
|
12
|
+
@check_merged = check_merged
|
11
13
|
end
|
12
14
|
|
13
15
|
def do!
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# update refs
|
18
|
-
git.remotes.each { |remote| git.fetch(remote, prune: true) } if @update_refs
|
19
|
-
|
20
|
-
unless git.branch('master').contains?(@branch)
|
21
|
-
unless TTY::Prompt.new.yes?("The branch #{@branch} was not merged to master. Would you like to remove it anyway?")
|
22
|
-
Worktree.logger.warn { "You've skipped removing the worktree #{@worktree}" }
|
23
|
-
return
|
24
|
-
end
|
16
|
+
if @check_merged && !git.branch('master').contains?(@branch)
|
17
|
+
raise NotMergedError.new("#{@branch} is not merged into master")
|
25
18
|
end
|
26
19
|
|
27
|
-
drop_db! if
|
20
|
+
drop_db! if @drop_db
|
28
21
|
|
29
22
|
# remove stale worktree
|
30
|
-
Worktree.run_command "git worktree remove #{@
|
23
|
+
Worktree.run_command "git worktree remove #{@project_dir}/#{@branch} --force", chdir: git.dir
|
31
24
|
|
32
25
|
# if remote branch exists then remove it also
|
33
|
-
if Git.ls_remote(git.dir)['remotes'].keys.include?("origin/#{@branch}")
|
34
|
-
|
35
|
-
|
36
|
-
end
|
26
|
+
if @drop_remote_branch && Git.ls_remote(git.dir)['remotes'].keys.include?("origin/#{@branch}")
|
27
|
+
git.push('origin', @branch, delete: true)
|
28
|
+
Worktree.logger.info { "Remote branch #{@branch} was deleted successfully." }
|
37
29
|
end
|
38
30
|
|
39
31
|
# remove local branch
|
40
32
|
git.branch(@branch).delete
|
33
|
+
rescue NotMergedError => e
|
34
|
+
Worktree.logger.error { e }
|
41
35
|
end
|
42
36
|
|
43
37
|
private
|
@@ -47,9 +41,8 @@ module Worktree
|
|
47
41
|
db_manager = db_manager_for(@branch)
|
48
42
|
return if db_manager.template == db_manager_master.template
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
44
|
+
db_manager.dropdb!
|
45
|
+
Worktree.logger.info { "Database #{db_manager.template} was dropped successfully." }
|
53
46
|
end
|
54
47
|
|
55
48
|
def db_manager_for(branch)
|
@@ -13,8 +13,9 @@ module Worktree
|
|
13
13
|
git.pull('upstream', 'master')
|
14
14
|
|
15
15
|
branches = Dir.entries(@project_dir).
|
16
|
-
|
17
|
-
|
16
|
+
select { |f| File.directory?("#{@project_dir}/#{f}}") }.
|
17
|
+
reject { |f| ['master', '.', '..'].include?(f) }
|
18
|
+
|
18
19
|
|
19
20
|
stale_branches = branches.select do |branch|
|
20
21
|
git.branch('master').contains?(branch)
|
@@ -24,7 +25,11 @@ module Worktree
|
|
24
25
|
|
25
26
|
stale_branches.each_with_index do |stale_branch, index|
|
26
27
|
Worktree.logger.info { "#{index + 1} of #{stale_branches.size}" }
|
27
|
-
Remove.new(stale_branch,
|
28
|
+
Remove.new(stale_branch,
|
29
|
+
project_dir: @project_dir,
|
30
|
+
drop_db: true,
|
31
|
+
drop_remote_branch: true,
|
32
|
+
check_merged: true).do!
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
data/lib/worktree/db_manager.rb
CHANGED
@@ -6,8 +6,8 @@ module Worktree
|
|
6
6
|
class DbManager
|
7
7
|
attr_reader :spec
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@spec = YAML.load_file(
|
9
|
+
def initialize(spec_file, environment = 'development')
|
10
|
+
@spec = YAML.load_file(spec_file)
|
11
11
|
@environment = environment
|
12
12
|
end
|
13
13
|
|
@@ -27,6 +27,14 @@ module Worktree
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def db_host
|
31
|
+
if multi?
|
32
|
+
environment_spec.dig('primary', 'host')
|
33
|
+
else
|
34
|
+
environment_spec['host']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
def template
|
31
39
|
if multi?
|
32
40
|
environment_spec.dig('primary', 'database')
|
@@ -37,18 +45,18 @@ module Worktree
|
|
37
45
|
|
38
46
|
def createdb!(db_name)
|
39
47
|
cmd = if db_port
|
40
|
-
"createdb -h
|
48
|
+
"createdb -h #{db_host} -p #{db_port} -T #{template} #{db_name}"
|
41
49
|
else
|
42
|
-
"createdb -h
|
50
|
+
"createdb -h #{db_host} -T #{template} #{db_name}"
|
43
51
|
end
|
44
52
|
Worktree.run_command cmd
|
45
53
|
end
|
46
54
|
|
47
55
|
def dropdb!
|
48
56
|
cmd = if db_port
|
49
|
-
"dropdb -h
|
57
|
+
"dropdb -h #{db_host} -p #{db_port} #{template}"
|
50
58
|
else
|
51
|
-
"dropdb -h
|
59
|
+
"dropdb -h #{db_host} #{template}"
|
52
60
|
end
|
53
61
|
Worktree.run_command cmd
|
54
62
|
end
|
data/lib/worktree/launcher.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
module Worktree
|
4
4
|
class Launcher # :nodoc:
|
5
|
-
def initialize(project_dir:, branch:)
|
5
|
+
def initialize(project_dir:, branch:, extra_vars: {})
|
6
6
|
@project_dir = project_dir
|
7
7
|
@branch = branch
|
8
8
|
@working_directory = "#{@project_dir}/#{@branch}".chomp('/')
|
9
|
+
@extra_vars = extra_vars.symbolize_keys
|
9
10
|
end
|
10
11
|
|
11
12
|
def launch!
|
@@ -16,20 +17,11 @@ module Worktree
|
|
16
17
|
|
17
18
|
def command
|
18
19
|
cmd = ENV.fetch('WORKTREE_LAUNCHER') { ENV.fetch('EDITOR', 'vim') }
|
19
|
-
format(cmd,
|
20
|
+
format(cmd, default_vars.merge(@extra_vars))
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
-
{
|
24
|
-
worktree_dir: @working_directory,
|
25
|
-
worktree_branch: @branch,
|
26
|
-
tmux_session_name: tmux_session_name
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
# tmux session name cannot contains . or :
|
31
|
-
def tmux_session_name
|
32
|
-
@branch.gsub(/\.|:/, '-')
|
23
|
+
def default_vars
|
24
|
+
{ path: @working_directory, branch: @branch }
|
33
25
|
end
|
34
26
|
end
|
35
27
|
end
|
data/lib/worktree/project.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Worktree
|
4
|
-
class Project
|
4
|
+
class Project # :nodoc:
|
5
5
|
def self.resolve(branch, project_dir: nil)
|
6
6
|
project_key = project_key_by_branch(branch)
|
7
7
|
# try to find project key by dir (cherry-pick or open case)
|
@@ -29,8 +29,6 @@ module Worktree
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
private
|
33
|
-
|
34
32
|
def self.project_key_by_branch(branch)
|
35
33
|
project_keys = Worktree::Config.config['projects'].keys
|
36
34
|
return nil if project_keys.empty?
|
@@ -52,5 +50,7 @@ module Worktree
|
|
52
50
|
end
|
53
51
|
project_key
|
54
52
|
end
|
53
|
+
|
54
|
+
private_class_method :project_key_by_branch, :project_key_by_dir
|
55
55
|
end
|
56
56
|
end
|
data/lib/worktree/version.rb
CHANGED
data/lib/worktree.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worktree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Gonchar
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: tty-prompt
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: zeitwerk
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,7 +164,7 @@ dependencies:
|
|
178
164
|
- - ">="
|
179
165
|
- !ruby/object:Gem::Version
|
180
166
|
version: '0'
|
181
|
-
description:
|
167
|
+
description:
|
182
168
|
email:
|
183
169
|
- igor.gonchar@gmail.com
|
184
170
|
executables:
|
@@ -195,6 +181,7 @@ files:
|
|
195
181
|
- lib/worktree/cli.rb
|
196
182
|
- lib/worktree/command.rb
|
197
183
|
- lib/worktree/command/add.rb
|
184
|
+
- lib/worktree/command/check_stale.rb
|
198
185
|
- lib/worktree/command/cherry_pick.rb
|
199
186
|
- lib/worktree/command/configure.rb
|
200
187
|
- lib/worktree/command/init.rb
|
@@ -219,7 +206,7 @@ homepage: https://github.com/gigorok/worktree
|
|
219
206
|
licenses:
|
220
207
|
- MIT
|
221
208
|
metadata: {}
|
222
|
-
post_install_message:
|
209
|
+
post_install_message:
|
223
210
|
rdoc_options: []
|
224
211
|
require_paths:
|
225
212
|
- lib
|
@@ -234,9 +221,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
221
|
- !ruby/object:Gem::Version
|
235
222
|
version: '0'
|
236
223
|
requirements: []
|
237
|
-
rubyforge_project:
|
224
|
+
rubyforge_project:
|
238
225
|
rubygems_version: 2.7.6.2
|
239
|
-
signing_key:
|
226
|
+
signing_key:
|
240
227
|
specification_version: 4
|
241
228
|
summary: Manage your projects by git working tree feature
|
242
229
|
test_files: []
|