git-bundle 1.0.10 → 1.0.15
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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/git_bundle.rb +4 -0
- data/lib/git_bundle/branch_config.rb +42 -0
- data/lib/git_bundle/cli.rb +12 -8
- data/lib/git_bundle/commands/checkout.rb +68 -0
- data/lib/git_bundle/commands/generate.rb +18 -0
- data/lib/git_bundle/commands/push.rb +14 -0
- data/lib/git_bundle/console.rb +6 -1
- data/lib/git_bundle/project.rb +4 -0
- data/lib/git_bundle/repository.rb +3 -3
- data/lib/git_bundle/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b776d0338d7edbb3ecb6a8e6c41f5489778f61e0d1bd5304d2dd131eb56371
|
4
|
+
data.tar.gz: e03aa0c6178a9c3a2a15e2f2103381226df4aba8e1da657aa00e8b74ef5f6b6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b137c0527c447066095068e005691b3e186fd21e7048513d91411795a20925f8cb4c7ad19daf34a4d4f048199d087d37065d67e5b5f4d5602f085e64c797850d
|
7
|
+
data.tar.gz: f6fa7c3fabcee252b780bcbbb476c260ddd634fea984b57d089538e70fcffa8de94999494ee78b81dede17f862b2b6b2a65425b7a73e4aac609fda58bb6b4482
|
data/Gemfile.lock
CHANGED
data/lib/git_bundle.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'bundler'
|
2
|
+
require 'yaml'
|
2
3
|
require 'git_bundle/version'
|
3
4
|
require 'git_bundle/console'
|
4
5
|
require 'git_bundle/shell'
|
5
6
|
require 'git_bundle/cli'
|
6
7
|
require 'git_bundle/repository'
|
7
8
|
require 'git_bundle/project'
|
9
|
+
require 'git_bundle/branch_config'
|
8
10
|
require 'git_bundle/commands/generic'
|
9
11
|
require 'git_bundle/commands/push'
|
12
|
+
require 'git_bundle/commands/checkout'
|
13
|
+
require 'git_bundle/commands/generate'
|
10
14
|
require 'git_bundle/commands/version'
|
@@ -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
|
data/lib/git_bundle/cli.rb
CHANGED
@@ -9,14 +9,18 @@ module GitBundle
|
|
9
9
|
|
10
10
|
def invoke(args)
|
11
11
|
case args[0]
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
24
|
end
|
21
25
|
rescue Bundler::GemfileNotFound => e
|
22
26
|
puts_error("Could not find Gemfile in the current directory")
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module GitBundle
|
2
|
+
module Commands
|
3
|
+
class Checkout
|
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
|
+
|
14
|
+
if @args.empty?
|
15
|
+
checkout_parallel(@project.dependant_repositories, @project.main_repository.branch)
|
16
|
+
|
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)}
|
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?
|
31
|
+
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>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def checkout(repo, branch, create_new: false, force: false)
|
37
|
+
if create_new
|
38
|
+
unless force
|
39
|
+
puts_repo_heading(repo)
|
40
|
+
puts_prompt("Create #{branch}? (Y/N)")
|
41
|
+
return unless STDIN.getch.upcase == 'Y'
|
42
|
+
end
|
43
|
+
args = ['checkout', '-b', branch]
|
44
|
+
else
|
45
|
+
args = ['checkout', branch]
|
46
|
+
end
|
47
|
+
|
48
|
+
output = repo.execute_git(args, color: true)
|
49
|
+
success = $?.exitstatus == 0
|
50
|
+
repo.refresh_branch
|
51
|
+
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
|
55
|
+
end
|
56
|
+
success
|
57
|
+
end
|
58
|
+
|
59
|
+
def checkout_parallel(repositories, fallback_branch)
|
60
|
+
parallel(repositories) do |repo|
|
61
|
+
output = repo.execute_git(['checkout', @project.branch_config.current&.dig(repo.name) || fallback_branch], color: true)
|
62
|
+
repo.refresh_branch
|
63
|
+
ExecutionResult.new($?.exitstatus != 0, output)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
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.dependant_repositories.each {|p| @project.branch_config.current[p.name] = p.branch}
|
14
|
+
@project.branch_config.save
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -66,6 +66,7 @@ module GitBundle
|
|
66
66
|
end
|
67
67
|
|
68
68
|
private
|
69
|
+
|
69
70
|
def prompt_confirm
|
70
71
|
if @project.main_repository.file_changed?('Gemfile')
|
71
72
|
puts_error 'Your Gemfile has uncommitted changes. Commit them first before pushing.'
|
@@ -74,6 +75,7 @@ module GitBundle
|
|
74
75
|
|
75
76
|
commits_to_push = false
|
76
77
|
upstream_branches_missing = []
|
78
|
+
diverged_repos = []
|
77
79
|
@project.repositories.each do |repo|
|
78
80
|
commits = repo.commits_not_pushed
|
79
81
|
puts_repo_heading(repo)
|
@@ -83,6 +85,7 @@ module GitBundle
|
|
83
85
|
puts 'No changes.'
|
84
86
|
else
|
85
87
|
commits_to_push = true
|
88
|
+
diverged_repos << repo if repo.branch != @project.main_repository.branch
|
86
89
|
puts commits
|
87
90
|
end
|
88
91
|
else
|
@@ -91,6 +94,17 @@ module GitBundle
|
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
97
|
+
if diverged_repos.any?
|
98
|
+
puts_prompt("\nThese repositories have changes and have diverged from the main application's branch (#{@project.main_repository.branch})")
|
99
|
+
puts_diverged_repos(diverged_repos)
|
100
|
+
puts_prompt("\nDo you want to continue? (Y/N)")
|
101
|
+
if STDIN.getch.upcase == 'Y'
|
102
|
+
puts ''
|
103
|
+
else
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
94
108
|
if !upstream_branches_missing.empty?
|
95
109
|
puts_prompt("Missing upstream branches (#{upstream_branches_missing.join(', ')}) will be created and changes pushed.")
|
96
110
|
puts_prompt('Do you want to continue? (Y/N)')
|
data/lib/git_bundle/console.rb
CHANGED
@@ -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
|
data/lib/git_bundle/project.rb
CHANGED
@@ -20,13 +20,13 @@ module GitBundle
|
|
20
20
|
@name = name
|
21
21
|
@path = path
|
22
22
|
@main = main_repository
|
23
|
-
@branch = fetch_branch
|
24
23
|
@locked_branch = locked_branch
|
25
24
|
@locked_revision = locked_revision
|
25
|
+
refresh_branch
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp
|
28
|
+
def refresh_branch
|
29
|
+
@branch = execute_git('rev-parse', '--abbrev-ref', 'HEAD').chomp
|
30
30
|
end
|
31
31
|
|
32
32
|
def locked_branch
|
data/lib/git_bundle/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Pretorius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -43,7 +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
|
48
|
+
- lib/git_bundle/commands/checkout.rb
|
49
|
+
- lib/git_bundle/commands/generate.rb
|
47
50
|
- lib/git_bundle/commands/generic.rb
|
48
51
|
- lib/git_bundle/commands/push.rb
|
49
52
|
- lib/git_bundle/commands/version.rb
|