worktree 0.2.1 → 0.2.2
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/command/add.rb +1 -1
- data/lib/worktree/command/cherry_pick.rb +1 -1
- data/lib/worktree/feature/clone_dbs.rb +1 -1
- data/lib/worktree/feature/copy_files.rb +5 -3
- data/lib/worktree/launcher.rb +7 -1
- data/lib/worktree/project.rb +37 -10
- data/lib/worktree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a21f0e1e12ffd3382234f57fc3abeff4f2816aa7f36897923ebe77e045fbb99
|
4
|
+
data.tar.gz: 79635e4cf96a885f5d0472887dc046e066db04427efaae495c65c97a38f00a00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c22b94b9bf4a33b14950574065963e5feec30ffeda94e376590dc2053f297c2fcee30cd087e227b0fcb4dc18903122a6bb92852e04b2ef5f60dd6d7df9f70fd
|
7
|
+
data.tar.gz: 8b988eeeb6ad543317f5bc117a6c8461a936f6b9e9ac1f84c2c9998403fefa843e78162163dfa697ee3c4c90a5ea43f659d68c89d4908511c2a24565448811ef
|
data/lib/worktree/command/add.rb
CHANGED
@@ -12,13 +12,15 @@ module Worktree
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def run!
|
15
|
-
|
16
|
-
paths = Worktree::Config.config.dig('projects', project_key, 'copy_files') || []
|
17
|
-
paths.each { |path| copy_file(path) }
|
15
|
+
files_to_copy.each { |path| copy_file(path) }
|
18
16
|
end
|
19
17
|
|
20
18
|
private
|
21
19
|
|
20
|
+
def files_to_copy
|
21
|
+
Worktree::Project.resolve(@branch, project_dir: @project_dir).copy_files
|
22
|
+
end
|
23
|
+
|
22
24
|
def copy_file(file)
|
23
25
|
master_path = "#{@project_dir}/master/#{file}"
|
24
26
|
if File.exist?(master_path)
|
data/lib/worktree/launcher.rb
CHANGED
@@ -22,8 +22,14 @@ module Worktree
|
|
22
22
|
def replace_vars
|
23
23
|
{
|
24
24
|
worktree_dir: @working_directory,
|
25
|
-
worktree_branch: @branch
|
25
|
+
worktree_branch: @branch,
|
26
|
+
tmux_session_name: tmux_session_name
|
26
27
|
}
|
27
28
|
end
|
29
|
+
|
30
|
+
# tmux session name cannot contains . or :
|
31
|
+
def tmux_session_name
|
32
|
+
@branch.gsub(/\.|:/, '-')
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/worktree/project.rb
CHANGED
@@ -2,22 +2,25 @@
|
|
2
2
|
|
3
3
|
module Worktree
|
4
4
|
class Project
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
(branch.match(re) || [])[1]
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.resolve(branch)
|
14
|
-
new(project_key_for(branch))
|
5
|
+
def self.resolve(branch, project_dir: nil)
|
6
|
+
project_key = project_key_by_branch(branch)
|
7
|
+
# try to find project key by dir (cherry-pick or open case)
|
8
|
+
project_key = project_key_by_dir(project_dir) if project_key.nil? && project_dir
|
9
|
+
new(project_key)
|
15
10
|
end
|
16
11
|
|
17
12
|
def initialize(key)
|
18
13
|
@key = key
|
19
14
|
end
|
20
15
|
|
16
|
+
def copy_files
|
17
|
+
if @key
|
18
|
+
Worktree::Config.config.dig('projects', @key, 'copy_files') || []
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
21
24
|
def root
|
22
25
|
if @key
|
23
26
|
Worktree::Config.config.dig('projects', @key, 'root').chomp('/')
|
@@ -25,5 +28,29 @@ module Worktree
|
|
25
28
|
Dir.pwd
|
26
29
|
end
|
27
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.project_key_by_branch(branch)
|
35
|
+
project_keys = Worktree::Config.config['projects'].keys
|
36
|
+
return nil if project_keys.empty?
|
37
|
+
|
38
|
+
re = Regexp.new("^(#{project_keys.join('|')})\-")
|
39
|
+
(branch.match(re) || [])[1]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.project_key_by_dir(dir)
|
43
|
+
project_keys = Worktree::Config.config['projects'].keys
|
44
|
+
return nil if project_keys.empty?
|
45
|
+
|
46
|
+
project_key = nil
|
47
|
+
Worktree::Config.config['projects'].each do |key, options|
|
48
|
+
if options['root'].chomp('/') == dir
|
49
|
+
project_key = key
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
project_key
|
54
|
+
end
|
28
55
|
end
|
29
56
|
end
|
data/lib/worktree/version.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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Gonchar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|