git-bundle 1.0.12 → 1.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44ca1512e752fc39175da8c2a9b585372a40b0aaf437e2cf8dfc3aa3f01c0798
4
- data.tar.gz: f648e9ef0701364938990823c8b477010cab190e28e37dcbf165643f36b42b1e
3
+ metadata.gz: 3be318a54723d942310503e63607c65c123d90c6523f8112bc9a33e47682f0de
4
+ data.tar.gz: dac2dade83c04bac6f2e716b5c2b0eab2c85ebd0d2d0faf078cf89fa641a23a1
5
5
  SHA512:
6
- metadata.gz: 4874bdf0f1b08b019820a377e8b98474a606eeae36f978280aa3f3cb99d38f2d5eb4dc5a4071b323e01b58a5150b7dd315fdd11d1640e44456c2caa5d93c5245
7
- data.tar.gz: 3c78b5ff23ae4412a114c1d60f3de6ae1b7d1745b59aff66eacfac6598871dd2697f37fbcd628d40ad43b49a7a9a3bf65fc08462221b2ece71448e6fcf1296ac
6
+ metadata.gz: 5d0b2b23d325b0e0abc79016868c998862234f8f029c0d171693883595706deec34ff2807a91d2eac39c786f48a4b72e1fa3354f8b04ee99bef7f4b8b32e5389
7
+ data.tar.gz: 5563b33d87947c8dc0861fb37c5101b4fc162b1d053f6939dcc75b8a5c1a57ff9c434065f1ef87e76ec4f2a22ea4557527ba71e76a7b4e176d4b09a0e4752ff6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-bundle (1.0.11)
4
+ git-bundle (1.0.12)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,7 +6,9 @@ require 'git_bundle/shell'
6
6
  require 'git_bundle/cli'
7
7
  require 'git_bundle/repository'
8
8
  require 'git_bundle/project'
9
+ require 'git_bundle/branch_config'
9
10
  require 'git_bundle/commands/generic'
10
11
  require 'git_bundle/commands/push'
11
12
  require 'git_bundle/commands/checkout'
13
+ require 'git_bundle/commands/generate'
12
14
  require 'git_bundle/commands/version'
@@ -0,0 +1,38 @@
1
+ module GitBundle
2
+ class BranchConfig
3
+ include GitBundle::Console
4
+ BRANCH_CONFIG_FILE = '.gitb.yml'
5
+
6
+ attr_reader :filename
7
+
8
+ def initialize(filename = nil)
9
+ @filename = filename || BRANCH_CONFIG_FILE
10
+ end
11
+
12
+ def path
13
+ File.join(Dir.pwd, filename)
14
+ end
15
+
16
+ def current
17
+ return @current if defined?(@current)
18
+ @current = read
19
+ end
20
+
21
+ def read
22
+ File.exists?(path) ? YAML.load_file(path) || {} : nil
23
+ end
24
+
25
+ def changed?
26
+ current != read
27
+ end
28
+
29
+ def save
30
+ File.open(path, 'w') {|file| file.write(current.to_yaml.lines[1..-1].join)}
31
+ if File.exists?(path)
32
+ puts "\t#{colorize('update', 34, bold: true)}\t#{filename}"
33
+ else
34
+ puts "\t#{colorize('create', 32, bold: true)}\t#{filename}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -9,16 +9,18 @@ module GitBundle
9
9
 
10
10
  def invoke(args)
11
11
  case args[0]
12
- when nil, '--help', 'help'
13
- puts `git #{args.join(' ')}`.gsub('git', 'gitb')
14
- when 'push'
15
- GitBundle::Commands::Push.new(@project, args[1..-1]).invoke
16
- when 'checkout'
17
- GitBundle::Commands::Checkout.new(@project, args[1..-1]).invoke
18
- when '--version'
19
- GitBundle::Commands::Version.new.invoke
20
- else
21
- GitBundle::Commands::Generic.new(@project, args).invoke
12
+ when nil, '--help', 'help'
13
+ puts `git #{args.join(' ')}`.gsub('git', 'gitb')
14
+ when 'push'
15
+ GitBundle::Commands::Push.new(@project, args[1..-1]).invoke
16
+ when 'checkout'
17
+ GitBundle::Commands::Checkout.new(@project, args[1..-1]).invoke
18
+ when 'generate', 'g'
19
+ GitBundle::Commands::Generate.new(@project, args[1..-1]).invoke
20
+ when '--version'
21
+ GitBundle::Commands::Version.new.invoke
22
+ else
23
+ GitBundle::Commands::Generic.new(@project, args).invoke
22
24
  end
23
25
  rescue Bundler::GemfileNotFound => e
24
26
  puts_error("Could not find Gemfile in the current directory")
@@ -1,7 +1,6 @@
1
1
  module GitBundle
2
2
  module Commands
3
3
  class Checkout
4
- BRANCH_CONFIG_FILE = '.gitb.yml'
5
4
  include GitBundle::Console
6
5
 
7
6
  def initialize(project, args)
@@ -19,13 +18,18 @@ module GitBundle
19
18
  if checkout(@project.main_repository, @args.first)
20
19
  checkout_parallel(@project.dependant_repositories, @args.first)
21
20
  end
22
-
23
21
  elsif @args.size == 2 && @args.first == '-b'
24
22
  if checkout(@project.main_repository, @args.last, create_new: true, force: true)
25
23
  @project.dependant_repositories.each {|r| checkout(r, @args.last, create_new: true)}
26
24
  end
25
+ @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)}
29
+ end
30
+ @project.branch_config.save if @project.branch_config.changed?
27
31
  else
28
- puts_error "Invalid arguments for checkout. Usage: \n\tgitb checkout\n\tgitb checkout <branch>\n\tgitb checkout -b <new_branch>"
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>"
29
33
  end
30
34
  end
31
35
 
@@ -46,33 +50,19 @@ module GitBundle
46
50
  repo.refresh_branch
47
51
  puts_repo_heading(repo) unless create_new && !force
48
52
  success ? puts(output) : puts_error(output)
49
- if create_new && success && branch_config
50
- branch_config[repo.name] = branch
51
- write_branch_config
53
+ if success && !repo.main && @project.branch_config.current && @project.branch_config.current[repo.name] != branch
54
+ @project.branch_config.current[repo.name] = branch
52
55
  end
53
56
  success
54
57
  end
55
58
 
56
59
  def checkout_parallel(repositories, fallback_branch)
57
60
  parallel(repositories) do |repo|
58
- output = repo.execute_git(['checkout', branch_config&.dig(repo.name) || fallback_branch], color: true)
61
+ output = repo.execute_git(['checkout', @project.branch_config.current&.dig(repo.name) || fallback_branch], color: true)
59
62
  repo.refresh_branch
60
63
  ExecutionResult.new($?.exitstatus != 0, output)
61
64
  end
62
65
  end
63
-
64
- def branch_config
65
- return @branch_config if defined?(@branch_config)
66
- @branch_config ||= File.exists?(config_file) ? YAML.load_file(config_file) || {} : nil
67
- end
68
-
69
- def config_file
70
- File.join(Dir.pwd, BRANCH_CONFIG_FILE)
71
- end
72
-
73
- def write_branch_config
74
- File.open(File.join(Dir.pwd, BRANCH_CONFIG_FILE), 'w') {|file| file.write(branch_config.to_yaml.lines[1..-1].join)}
75
- end
76
66
  end
77
67
  end
78
68
  end
@@ -0,0 +1,18 @@
1
+ module GitBundle
2
+ module Commands
3
+ class Generate
4
+ include GitBundle::Console
5
+
6
+ def initialize(project, args)
7
+ @project = project
8
+ @args = args
9
+ end
10
+
11
+ def invoke
12
+ @project.load_dependant_repositories
13
+ @project.repositories.each {|p| @project.branch_config.current[p.name] = p.branch}
14
+ @project.branch_config.save
15
+ end
16
+ end
17
+ end
18
+ end
@@ -30,6 +30,10 @@ module GitBundle
30
30
  end
31
31
  end
32
32
 
33
+ def branch_config
34
+ @branch_config ||= GitBundle::BranchConfig.new
35
+ end
36
+
33
37
  def repositories
34
38
  @dependant_repositories + [@main_repository]
35
39
  end
@@ -1,3 +1,3 @@
1
1
  module GitBundle
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.13'
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.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Pretorius
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-23 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -43,8 +43,10 @@ files:
43
43
  - bin/gitb
44
44
  - git-bundle.gemspec
45
45
  - lib/git_bundle.rb
46
+ - lib/git_bundle/branch_config.rb
46
47
  - lib/git_bundle/cli.rb
47
48
  - lib/git_bundle/commands/checkout.rb
49
+ - lib/git_bundle/commands/generate.rb
48
50
  - lib/git_bundle/commands/generic.rb
49
51
  - lib/git_bundle/commands/push.rb
50
52
  - lib/git_bundle/commands/version.rb