worktree 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae13288c9a0d09cf33b342bbcbd6cba9153713f5589afd88578f828d74e781f2
4
- data.tar.gz: 58195a0bddf0d7c7310e8fdc01cf5a890f4006c57ea638754435cb82ad5380a0
3
+ metadata.gz: 5a21f0e1e12ffd3382234f57fc3abeff4f2816aa7f36897923ebe77e045fbb99
4
+ data.tar.gz: 79635e4cf96a885f5d0472887dc046e066db04427efaae495c65c97a38f00a00
5
5
  SHA512:
6
- metadata.gz: f8c31028b7da48adf4137fe78b1b66c35d708c6ec78cb10f579540bb3a358c0fa00203d7768151d81eef1e09be9fc3ac102da87f6c604f003d082f5aedf1effd
7
- data.tar.gz: ba0eff802cf57b7ea745a54a08a1fe2c845bdbbd30622a0de2aaba1316c035a61796013ebe5bfe163d2e61fa5c4bfd6a446e794fc938237ff5715e9d3853ae20
6
+ metadata.gz: 2c22b94b9bf4a33b14950574065963e5feec30ffeda94e376590dc2053f297c2fcee30cd087e227b0fcb4dc18903122a6bb92852e04b2ef5f60dd6d7df9f70fd
7
+ data.tar.gz: 8b988eeeb6ad543317f5bc117a6c8461a936f6b9e9ac1f84c2c9998403fefa843e78162163dfa697ee3c4c90a5ea43f659d68c89d4908511c2a24565448811ef
@@ -45,7 +45,7 @@ module Worktree
45
45
  end
46
46
 
47
47
  def clone_dbs
48
- if File.exist?("#{@project_dir}/master/config/database.yml")
48
+ if File.exist?("#{@project_dir}/#{@branch}/config/database.yml")
49
49
  Feature::CloneDbs.new(
50
50
  project_dir: @project_dir,
51
51
  branch: @branch
@@ -47,7 +47,7 @@ module Worktree
47
47
  end
48
48
 
49
49
  def clone_dbs
50
- if File.exist?("#{@project_dir}/master/config/database.yml")
50
+ if File.exist?("#{@project_dir}/#{@branch}/config/database.yml")
51
51
  Feature::CloneDbs.new(
52
52
  project_dir: @project_dir,
53
53
  branch: @branch
@@ -12,7 +12,7 @@ module Worktree
12
12
  end
13
13
 
14
14
  def run!
15
- @db_manager = DbManager.new("#{@project_dir}/master/config/database.yml")
15
+ @db_manager = DbManager.new("#{@project_dir}/#{@branch}/config/database.yml")
16
16
  @db_manager.createdb!(db_name)
17
17
 
18
18
  write!
@@ -12,13 +12,15 @@ module Worktree
12
12
  end
13
13
 
14
14
  def run!
15
- project_key = Worktree::Project.project_key_for(@branch)
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)
@@ -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
@@ -2,22 +2,25 @@
2
2
 
3
3
  module Worktree
4
4
  class Project
5
- def self.project_key_for(branch)
6
- project_keys = Worktree::Config.config['projects'].keys
7
- return nil if project_keys.empty?
8
-
9
- re = Regexp.new("^(#{project_keys.join('|')})\-")
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Worktree
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
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.1
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-19 00:00:00.000000000 Z
11
+ date: 2020-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport