git-bundle 1.0.16 → 1.0.18

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: b3695e18c4ce00b28d229d3a0c471066be6fabb1117b2a363f2fa447766b8c4a
4
- data.tar.gz: 27ef1522b91ef11574b109096a36fb62f41990630de84d9b31c97110e1da2523
3
+ metadata.gz: 5d5e435d1dd24f9d955632075556705ba3503475ef4bea749b8c3814c473b6f1
4
+ data.tar.gz: 452aa1be724f46937ee68975f6813c622470fb50d3d2302cc18c0f239c4916ca
5
5
  SHA512:
6
- metadata.gz: 4322df4990c97e2fd8f6b41fda7471ace527a89c1f4aab6868e679493a88bc09df39a32bed5d3a5045b4b912497b6a3343ca796b1751582cb41ac8e31c60f358
7
- data.tar.gz: d6b2258ae386d3b39bcd9757e9c5f2dc3e902a6b5e28152f027d6050180053dc338915f550baa7ba5a6855e0698e7db5593bc0359ec071183a4f2d8369318aa7
6
+ metadata.gz: 8fdbd6c5a9c6eb2a414384828439eb249e7692a6987912b00e04f1e037893f2a1724f3c0c572d30cbb5e30d31bfa0d1801e536faea1bda027dfec7430d85fdcc
7
+ data.tar.gz: 235a9d14af3802d74e22ac5cddda6e62a4baf9e1ed00fb85920c10511a7a6d747ba5b8470984e554fa659090b1e3ffa439ecc04cb84611044c2f962f45443d10
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-bundle (1.0.15)
4
+ git-bundle (1.0.17)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -18,6 +18,24 @@ module GitBundle
18
18
  @current = read
19
19
  end
20
20
 
21
+ def remote(repo_name)
22
+ source = current[repo_name]
23
+ if source.include?(' ')
24
+ source.split(' ').first
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def branch(repo_name)
31
+ source = current[repo_name]
32
+ if source&.include?(' ')
33
+ source.split(' ').last
34
+ else
35
+ source
36
+ end
37
+ end
38
+
21
39
  def read
22
40
  File.exists?(path) ? YAML.load_file(path) || {} : nil
23
41
  end
@@ -28,7 +46,7 @@ module GitBundle
28
46
 
29
47
  def save
30
48
  if changed?
31
- File.open(path, 'w') {|file| file.write(current.to_yaml.lines[1..-1].join)}
49
+ File.open(path, 'w') { |file| file.write(current.to_yaml.lines[1..-1].join) }
32
50
  if File.exists?(path)
33
51
  puts "\t#{colorize('update', 34, bold: true)}\t#{filename}"
34
52
  else
@@ -10,55 +10,68 @@ module GitBundle
10
10
 
11
11
  def invoke
12
12
  @project.load_dependant_repositories
13
+ remaining_args = @args.dup
14
+ flag = remaining_args.first&.chars&.first == "-" ? remaining_args.shift : nil
15
+ branch = remaining_args.shift
13
16
 
14
- if @args.empty?
15
- checkout_parallel(@project.dependant_repositories, @project.main_repository.branch)
17
+ if remaining_args.any? || (flag && branch.nil?)
18
+ puts_error "Invalid arguments for checkout. Usage: \n\tgitb checkout\n\tgitb checkout <branch>\n\tgitb checkout <remote/branch>\n\tgitb checkout -b <new branch>\n\tgitb checkout -a <force branch all repositories>"
19
+ return
20
+ end
16
21
 
17
- elsif @args.size == 1
18
- if checkout(@project.main_repository, @args.first)
19
- checkout_parallel(@project.dependant_repositories, @args.first)
20
- end
21
- elsif @args.size == 2 && @args.first == '-b'
22
- if checkout(@project.main_repository, @args.last, create_new: true, force: true)
23
- @project.dependant_repositories.each {|r| checkout(r, @args.last, create_new: true)}
22
+ case
23
+ when flag == "-a" || flag == "--all"
24
+ if checkout(@project.main_repository, branch)
25
+ @project.dependant_repositories.each { |r| checkout(r, branch) }
24
26
  end
25
27
  @project.branch_config.save if @project.branch_config.changed?
26
- elsif @args.size == 2 && (@args.first == '-a' || @args.first == '--all')
27
- if checkout(@project.main_repository, @args.last)
28
- @project.dependant_repositories.each {|r| checkout(r, @args.last)}
28
+ when flag == "-b"
29
+ if checkout(@project.main_repository, branch, create_new: true, force: true)
30
+ @project.dependant_repositories.each { |r| checkout(r, branch, create_new: true) }
29
31
  end
30
32
  @project.branch_config.save if @project.branch_config.changed?
33
+ when branch.nil?
34
+ checkout_parallel(@project.dependant_repositories, fallback_branch: @project.main_repository.branch)
31
35
  else
32
- puts_error "Invalid arguments for checkout. Usage: \n\tgitb checkout\n\tgitb checkout <branch>\n\tgitb checkout -b <new branch>\n\tgitb checkout -a <force branch all repositories>"
36
+ if checkout(@project.main_repository, branch)
37
+ checkout_parallel(@project.dependant_repositories, fallback_branch: branch)
38
+ end
33
39
  end
34
40
  end
35
41
 
36
42
  def checkout(repo, branch, create_new: false, force: false)
43
+ args = ['checkout']
37
44
  if create_new
38
45
  unless force
39
46
  puts_repo_heading(repo)
40
47
  puts_prompt("Create #{branch}? (Y/N)")
41
48
  return unless STDIN.getch.upcase == 'Y'
42
49
  end
43
- args = ['checkout', '-b', branch]
44
- else
45
- args = ['checkout', branch]
50
+ args << '-b'
46
51
  end
52
+ args << branch
47
53
 
48
54
  output = repo.execute_git(args, color: true)
49
55
  success = $?.exitstatus == 0
50
56
  repo.refresh_branch
51
57
  puts_repo_heading(repo) unless create_new && !force
52
- success ? puts(output) : puts_error(output)
53
- if success && !repo.main && @project.branch_config.current && @project.branch_config.current[repo.name] != branch
54
- @project.branch_config.current[repo.name] = branch
58
+ if success && !repo.main && create_new && @project.branch_config.current
59
+ old_remote = @project.branch_config.remote(repo.name)
60
+ if old_remote
61
+ @project.branch_config.current[repo.name] = "#{old_remote} #{branch}"
62
+ else
63
+ @project.branch_config.current[repo.name] = branch
64
+ end
65
+ puts(output)
66
+ else
67
+ puts_error(output)
55
68
  end
56
69
  success
57
70
  end
58
71
 
59
- def checkout_parallel(repositories, fallback_branch)
72
+ def checkout_parallel(repositories, fallback_branch: nil)
60
73
  parallel(repositories) do |repo|
61
- output = repo.execute_git(['checkout', @project.branch_config.current&.dig(repo.name) || fallback_branch], color: true)
74
+ output = repo.execute_git(['checkout', @project.branch_config.branch(repo.name) || fallback_branch], color: true)
62
75
  repo.refresh_branch
63
76
  ExecutionResult.new($?.exitstatus != 0, output)
64
77
  end
@@ -16,7 +16,7 @@ module GitBundle
16
16
 
17
17
  def remote_branch_reference(repository)
18
18
  if repository.remote
19
- "#{repository.remote}/#{repository.branch}"
19
+ "#{repository.remote} #{repository.branch}"
20
20
  else
21
21
  repository.branch
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module GitBundle
2
- VERSION = '1.0.16'
2
+ VERSION = '1.0.18'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Pretorius
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-06 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler