git-bundle 1.0.12 → 1.0.16

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: 44ca1512e752fc39175da8c2a9b585372a40b0aaf437e2cf8dfc3aa3f01c0798
4
- data.tar.gz: f648e9ef0701364938990823c8b477010cab190e28e37dcbf165643f36b42b1e
3
+ metadata.gz: b3695e18c4ce00b28d229d3a0c471066be6fabb1117b2a363f2fa447766b8c4a
4
+ data.tar.gz: 27ef1522b91ef11574b109096a36fb62f41990630de84d9b31c97110e1da2523
5
5
  SHA512:
6
- metadata.gz: 4874bdf0f1b08b019820a377e8b98474a606eeae36f978280aa3f3cb99d38f2d5eb4dc5a4071b323e01b58a5150b7dd315fdd11d1640e44456c2caa5d93c5245
7
- data.tar.gz: 3c78b5ff23ae4412a114c1d60f3de6ae1b7d1745b59aff66eacfac6598871dd2697f37fbcd628d40ad43b49a7a9a3bf65fc08462221b2ece71448e6fcf1296ac
6
+ metadata.gz: 4322df4990c97e2fd8f6b41fda7471ace527a89c1f4aab6868e679493a88bc09df39a32bed5d3a5045b4b912497b6a3343ca796b1751582cb41ac8e31c60f358
7
+ data.tar.gz: d6b2258ae386d3b39bcd9757e9c5f2dc3e902a6b5e28152f027d6050180053dc338915f550baa7ba5a6855e0698e7db5593bc0359ec071183a4f2d8369318aa7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-bundle (1.0.11)
4
+ git-bundle (1.0.15)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,42 @@
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
+ if changed?
31
+ File.open(path, 'w') {|file| file.write(current.to_yaml.lines[1..-1].join)}
32
+ if File.exists?(path)
33
+ puts "\t#{colorize('update', 34, bold: true)}\t#{filename}"
34
+ else
35
+ puts "\t#{colorize('create', 32, bold: true)}\t#{filename}"
36
+ end
37
+ else
38
+ puts "\t#{colorize('identical', 34, bold: true)}\t#{filename}"
39
+ end
40
+ end
41
+ end
42
+ 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,26 @@
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.dependant_repositories.each { |repo| @project.branch_config.current[repo.name] = remote_branch_reference(repo) }
14
+ @project.branch_config.save
15
+ end
16
+
17
+ def remote_branch_reference(repository)
18
+ if repository.remote
19
+ "#{repository.remote}/#{repository.branch}"
20
+ else
21
+ repository.branch
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -11,7 +11,12 @@ module GitBundle
11
11
 
12
12
  def invoke
13
13
  @project.load_dependant_repositories
14
- return false unless prompt_confirm
14
+ remote = @args.first || @project.main_repository.remote
15
+ unless remote
16
+ puts_error "New branch '#{@project.main_repository.branch}' is not tracking a remote branch. Specify which remote to push to, example:\n\tgitb push origin"
17
+ return false
18
+ end
19
+ return false unless prompt_confirm(remote)
15
20
 
16
21
  main_repository = @project.main_repository
17
22
 
@@ -22,7 +27,7 @@ module GitBundle
22
27
  end.join(', ')
23
28
 
24
29
  stale_commits_description = ''
25
- stale_repos.select(&:upstream_branch_exists?).each do |repo|
30
+ stale_repos.select { |r| r.upstream_branch_exists? }.each do |repo|
26
31
  stale_commits_description << "== #{repo.name} ==\n"
27
32
  stale_commits_description << repo.stale_commits
28
33
  stale_commits_description << "\n\n"
@@ -51,7 +56,11 @@ module GitBundle
51
56
  @project.dependant_repositories.select { |repo| repo.commits_not_pushed? }.each do |repo|
52
57
  puts_repo_heading(repo)
53
58
 
54
- create_upstream = !repo.upstream_branch_exists?
59
+ create_upstream = repo.upstream_branch_exists? ? nil : remote
60
+ if create_upstream && !repo.remote_exists?(create_upstream)
61
+ puts_error "Invalid remote: #{remote}"
62
+ return false
63
+ end
55
64
  unless repo.push(@args, create_upstream: create_upstream)
56
65
  puts_error "Failed to push changes of #{repo.name}. Try pulling the latest changes or resolve conflicts first."
57
66
  return false
@@ -59,14 +68,15 @@ module GitBundle
59
68
  end
60
69
 
61
70
  puts_repo_heading(main_repository)
62
- create_upstream = !main_repository.upstream_branch_exists?
71
+ create_upstream = main_repository.upstream_branch_exists? ? nil : remote
63
72
  unless main_repository.push(@args, create_upstream: create_upstream)
64
73
  puts_error "Failed to push changes of #{main_repository.name}. Try pulling the latest changes or resolve conflicts first."
65
74
  end
66
75
  end
67
76
 
68
77
  private
69
- def prompt_confirm
78
+
79
+ def prompt_confirm(remote)
70
80
  if @project.main_repository.file_changed?('Gemfile')
71
81
  puts_error 'Your Gemfile has uncommitted changes. Commit them first before pushing.'
72
82
  return false
@@ -74,6 +84,7 @@ module GitBundle
74
84
 
75
85
  commits_to_push = false
76
86
  upstream_branches_missing = []
87
+ diverged_repos = []
77
88
  @project.repositories.each do |repo|
78
89
  commits = repo.commits_not_pushed
79
90
  puts_repo_heading(repo)
@@ -83,11 +94,23 @@ module GitBundle
83
94
  puts 'No changes.'
84
95
  else
85
96
  commits_to_push = true
97
+ diverged_repos << repo if repo.branch != @project.main_repository.branch
86
98
  puts commits
87
99
  end
88
100
  else
89
101
  upstream_branches_missing << repo.name
90
- puts 'Remote branch does not exist yet.'
102
+ puts "Remote branch #{remote}/#{repo.branch} does not exist yet."
103
+ end
104
+ end
105
+
106
+ if diverged_repos.any?
107
+ puts_prompt("\nThese repositories have changes and have diverged from the main application's branch (#{@project.main_repository.branch})")
108
+ puts_diverged_repos(diverged_repos)
109
+ puts_prompt("\nDo you want to continue? (Y/N)")
110
+ if STDIN.getch.upcase == 'Y'
111
+ puts ''
112
+ else
113
+ return false
91
114
  end
92
115
  end
93
116
 
@@ -23,6 +23,10 @@ module GitBundle
23
23
  puts colorize("\n=== #{repo.name} (#{repo.branch} ⇒ #{new_branch})", COLORS[:heading], true)
24
24
  end
25
25
 
26
+ def puts_diverged_repos(repos)
27
+ repos.each { |repo| puts colorize(" #{repo.name} (#{repo.branch})", COLORS[:prompt], true) }
28
+ end
29
+
26
30
  def puts_heading(text)
27
31
  puts colorize("\n=== #{text}", COLORS[:heading])
28
32
  end
@@ -88,6 +92,7 @@ module GitBundle
88
92
  end
89
93
 
90
94
  private
95
+
91
96
  def colorize(text, color_code, bold = false)
92
97
  if bold
93
98
  "\e[1m\e[#{color_code}m#{text}\e[0m"
@@ -96,4 +101,4 @@ module GitBundle
96
101
  end
97
102
  end
98
103
  end
99
- end
104
+ 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
@@ -5,6 +5,7 @@ module GitBundle
5
5
  attr_reader :name,
6
6
  :path,
7
7
  :main,
8
+ :remote,
8
9
  :branch,
9
10
  :locked_branch
10
11
 
@@ -26,6 +27,7 @@ module GitBundle
26
27
  end
27
28
 
28
29
  def refresh_branch
30
+ @remote = execute(*git_command('rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'), silence_err: true).split('/').first
29
31
  @branch = execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp
30
32
  end
31
33
 
@@ -50,8 +52,12 @@ module GitBundle
50
52
  $?.exitstatus == 0
51
53
  end
52
54
 
55
+ def remote_exists?(remote_name)
56
+ execute_git('remote').split("\n").include?(remote_name)
57
+ end
58
+
53
59
  def upstream_branch_exists?
54
- reference_exists?("origin/#{branch}")
60
+ reference_exists?("#{remote}/#{branch}")
55
61
  end
56
62
 
57
63
  def stale_commits
@@ -68,15 +74,16 @@ module GitBundle
68
74
  end
69
75
 
70
76
  def commits_not_pushed
71
- execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "origin/#{branch}..#{branch}")
77
+ execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', "#{remote}/#{branch}..#{branch}")
72
78
  end
73
79
 
74
80
  def commits_not_pushed_count
75
- execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "origin/#{branch}..#{branch}").to_i
81
+ execute_git('rev-list', '--pretty=oneline', '--abbrev-commit', '--count', "#{remote}/#{branch}..#{branch}").to_i
76
82
  end
77
83
 
78
- def push(args, create_upstream: false)
79
- args = args.dup + ['--set-upstream', 'origin', branch] if create_upstream
84
+ # Example: push([], create_upstream: 'origin')
85
+ def push(args, create_upstream: nil)
86
+ args = args.dup + ['--set-upstream', create_upstream, branch] if create_upstream
80
87
  execute_git_output('push', args)
81
88
  $?.exitstatus == 0 || (create_upstream && $?.exitstatus == 128)
82
89
  end
@@ -17,11 +17,12 @@ module GitBundle
17
17
  execute_pipe(*args).each_line { |line| puts line.chomp }
18
18
  end
19
19
 
20
- def execute(*args)
20
+ def execute(*args, silence_err: false)
21
21
  puts args.map { |arg| "'#{arg}'" }.join(' ') if ENV['DEBUG'] == 'true'
22
22
 
23
23
  pipe_out, pipe_in = IO.pipe
24
- system *args, out: pipe_in, err: pipe_in
24
+ pipe_err_in = silence_err ? File::NULL : pipe_in
25
+ system *args, out: pipe_in, err: pipe_err_in
25
26
  pipe_in.close
26
27
  pipe_out.read
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module GitBundle
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.16'
3
3
  end
data/lib/git_bundle.rb CHANGED
@@ -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'
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.16
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: 2021-12-06 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
@@ -72,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  - !ruby/object:Gem::Version
73
75
  version: '0'
74
76
  requirements: []
75
- rubyforge_project:
76
- rubygems_version: 2.7.6
77
+ rubygems_version: 3.1.4
77
78
  signing_key:
78
79
  specification_version: 4
79
80
  summary: Simplifies working with gems from git repositories in combination with local