git-bundle 1.0.13 → 1.0.18

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: 3be318a54723d942310503e63607c65c123d90c6523f8112bc9a33e47682f0de
4
- data.tar.gz: dac2dade83c04bac6f2e716b5c2b0eab2c85ebd0d2d0faf078cf89fa641a23a1
3
+ metadata.gz: 5d5e435d1dd24f9d955632075556705ba3503475ef4bea749b8c3814c473b6f1
4
+ data.tar.gz: 452aa1be724f46937ee68975f6813c622470fb50d3d2302cc18c0f239c4916ca
5
5
  SHA512:
6
- metadata.gz: 5d0b2b23d325b0e0abc79016868c998862234f8f029c0d171693883595706deec34ff2807a91d2eac39c786f48a4b72e1fa3354f8b04ee99bef7f4b8b32e5389
7
- data.tar.gz: 5563b33d87947c8dc0861fb37c5101b4fc162b1d053f6939dcc75b8a5c1a57ff9c434065f1ef87e76ec4f2a22ea4557527ba71e76a7b4e176d4b09a0e4752ff6
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.12)
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
@@ -27,11 +45,15 @@ module GitBundle
27
45
  end
28
46
 
29
47
  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}"
48
+ if changed?
49
+ File.open(path, 'w') { |file| file.write(current.to_yaml.lines[1..-1].join) }
50
+ if File.exists?(path)
51
+ puts "\t#{colorize('update', 34, bold: true)}\t#{filename}"
52
+ else
53
+ puts "\t#{colorize('create', 32, bold: true)}\t#{filename}"
54
+ end
33
55
  else
34
- puts "\t#{colorize('create', 32, bold: true)}\t#{filename}"
56
+ puts "\t#{colorize('identical', 34, bold: true)}\t#{filename}"
35
57
  end
36
58
  end
37
59
  end
@@ -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
@@ -10,9 +10,17 @@ module GitBundle
10
10
 
11
11
  def invoke
12
12
  @project.load_dependant_repositories
13
- @project.repositories.each {|p| @project.branch_config.current[p.name] = p.branch}
13
+ @project.dependant_repositories.each { |repo| @project.branch_config.current[repo.name] = remote_branch_reference(repo) }
14
14
  @project.branch_config.save
15
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
16
24
  end
17
25
  end
18
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
@@ -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.13'
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.13
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: 2020-05-25 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
@@ -74,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.7.6
77
+ rubygems_version: 3.1.4
79
78
  signing_key:
80
79
  specification_version: 4
81
80
  summary: Simplifies working with gems from git repositories in combination with local