git-bundle 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -0
- data/lib/git_bundle.rb +2 -1
- data/lib/git_bundle/cli.rb +4 -23
- data/lib/git_bundle/commands/generic.rb +23 -0
- data/lib/git_bundle/commands/push.rb +96 -0
- data/lib/git_bundle/console.rb +9 -6
- data/lib/git_bundle/repository.rb +3 -1
- data/lib/git_bundle/version.rb +1 -1
- metadata +4 -2
- data/lib/git_bundle/push.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f8a6dbac04e7df74fd20844a8d1b3d9644f1481
|
4
|
+
data.tar.gz: 73c8387f701edb2c52daa89c5dcabfd11623e5d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c5d5533464c4aef6dc674c18f70870926955eeb7c3b26c8a511bf73fee90495182f22955639ec8e40f5ec6f90c0a7964eb3ad011409c81fbd78d73512dcadb5
|
7
|
+
data.tar.gz: 9670f36cc2eedc9742e128c474261b5376a4e0031bfc650f46f1182d8339cb448ff6f963de8d8ad33e7a315f4dbdaa1fe8405616321cbf32686a60c89b032d17
|
data/Gemfile.lock
ADDED
data/lib/git_bundle.rb
CHANGED
data/lib/git_bundle/cli.rb
CHANGED
@@ -12,39 +12,20 @@ module GitBundle
|
|
12
12
|
when nil, '--help', 'help'
|
13
13
|
puts `git #{args.join(' ')}`.gsub('git', 'gitb')
|
14
14
|
when 'push'
|
15
|
-
|
16
|
-
push.invoke if push.prompt_confirm
|
15
|
+
GitBundle::Commands::Push.new(@repositories, args[1..-1]).invoke
|
17
16
|
else
|
18
|
-
|
17
|
+
GitBundle::Commands::Generic.new(@repositories, args).invoke
|
19
18
|
end
|
20
|
-
|
21
|
-
puts_error @errors.join('\n') unless @errors.empty?
|
22
|
-
end
|
23
|
-
|
24
|
-
def exec_all(*argv)
|
25
|
-
exec_errors = []
|
26
|
-
@repositories.each do |repo|
|
27
|
-
puts_repo_heading(repo)
|
28
|
-
puts repo.execute_git(argv.join(' '))
|
29
|
-
exec_errors << repo.name unless $?.exitstatus == 0
|
30
|
-
end
|
31
|
-
|
32
|
-
@errors << "Command failed in #{exec_errors.join(', ')}." unless exec_errors.empty?
|
33
19
|
end
|
34
20
|
|
35
21
|
private
|
36
22
|
def load_repositories
|
37
23
|
@repositories = []
|
38
|
-
|
39
|
-
lockfile_content = Bundler.read_file(Bundler.default_lockfile)
|
40
|
-
all_specs = Bundler::LockfileParser.new(lockfile_content).specs
|
24
|
+
if Bundler.locked_gems
|
41
25
|
Bundler.settings.local_overrides.each do |name, path|
|
42
|
-
spec =
|
26
|
+
spec = Bundler.locked_gems.specs.find { |s| s.name == name }
|
43
27
|
@repositories << GitBundle::Repository.new_dependant(spec.name, path, spec.source.branch, spec.source.revision) if spec
|
44
28
|
end
|
45
|
-
|
46
|
-
rescue Bundler::LockfileError
|
47
|
-
@errors << "Error reading #{Bundler.default_lockfile}: \n\t#{error.message}."
|
48
29
|
end
|
49
30
|
|
50
31
|
@repositories << GitBundle::Repository.new_main(File.basename(Dir.getwd), Dir.getwd)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GitBundle
|
2
|
+
module Commands
|
3
|
+
class Generic
|
4
|
+
include GitBundle::Console
|
5
|
+
|
6
|
+
def initialize(repositories, args)
|
7
|
+
@repositories = repositories
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def invoke
|
12
|
+
errors = []
|
13
|
+
@repositories.each do |repo|
|
14
|
+
puts_repo_heading(repo)
|
15
|
+
puts repo.execute_git(@args.join(' '))
|
16
|
+
errors << repo.name unless $?.exitstatus == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
puts_error "Command failed in #{errors.join(', ')}." unless errors.empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module GitBundle
|
2
|
+
module Commands
|
3
|
+
class Push
|
4
|
+
include GitBundle::Console
|
5
|
+
|
6
|
+
def initialize(repositories, args)
|
7
|
+
@repositories = repositories
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def invoke
|
12
|
+
return false unless prompt_confirm
|
13
|
+
|
14
|
+
lockfile = Bundler.default_lockfile.basename.to_s
|
15
|
+
if gemfile_lock_stale?
|
16
|
+
puts "Local gems were updated. Building new #{lockfile} with bundle install."
|
17
|
+
unless build_gemfile_lock
|
18
|
+
puts_error 'Bundle install failed. Please run it manually before trying to push changes.'
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
combined_messages = @repositories.map { |repo| repo.commit_messages_not_pushed }.uniq.join("\n\n")
|
24
|
+
@repositories.reject { |repo| repo.main || repo.commits_not_pushed.empty? }.each do |repo|
|
25
|
+
puts_repo_heading(repo)
|
26
|
+
unless repo.push(@args)
|
27
|
+
puts_error "Failed to push changes of #{repo.name}. Try pulling the latest changes or resolve conflicts first."
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
puts_repo_heading(main_repository)
|
33
|
+
if main_repository.file_changed?(lockfile)
|
34
|
+
main_repository.add_file(lockfile)
|
35
|
+
main_repository.commit("Updated Gemfile.lock to include changes: #{combined_messages}", lockfile)
|
36
|
+
end
|
37
|
+
|
38
|
+
unless main_repository.push(@args)
|
39
|
+
puts_error "Failed to push changes of #{main_repository.name}. Try pulling the latest changes or resolve conflicts first."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def prompt_confirm
|
45
|
+
if main_repository.file_changed?('Gemfile')
|
46
|
+
puts_error 'Your Gemfile has uncommitted changes. Commit them first before pushing.'
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
commits_to_push = false
|
51
|
+
@repositories.each do |repo|
|
52
|
+
commits = repo.commits_not_pushed
|
53
|
+
puts_repo_heading(repo)
|
54
|
+
|
55
|
+
if commits.empty?
|
56
|
+
puts 'No changes.'
|
57
|
+
else
|
58
|
+
commits_to_push = true
|
59
|
+
puts commits
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if commits_to_push
|
64
|
+
puts_prompt('Are you sure you want to push these changes? (Y/N)')
|
65
|
+
|
66
|
+
elsif gemfile_lock_stale?
|
67
|
+
puts_prompt('Although you don\'t have any commits to push, your Gemfile.lock needs to be rebuilt, committed and pushed.')
|
68
|
+
puts_prompt('Do you want to continue? (Y/N)')
|
69
|
+
|
70
|
+
elsif main_repository.file_changed?('Gemfile.lock')
|
71
|
+
puts_prompt('Although you don\'t have any commits to push, your Gemfile.lock needs to be committed and pushed.')
|
72
|
+
puts_prompt('Do you want to continue? (Y/N)')
|
73
|
+
else
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
|
77
|
+
STDIN.getch.upcase == 'Y'
|
78
|
+
end
|
79
|
+
|
80
|
+
def main_repository
|
81
|
+
@repositories.find { |repo| repo.main }
|
82
|
+
end
|
83
|
+
|
84
|
+
def gemfile_lock_stale?
|
85
|
+
@repositories.any? { |repo| repo.revision != repo.locked_revision }
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_gemfile_lock
|
89
|
+
Dir.chdir(main_repository.path) do
|
90
|
+
puts `bundle install --quiet`
|
91
|
+
return $?.exitstatus == 0
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/git_bundle/console.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module GitBundle
|
2
2
|
module Console
|
3
|
-
COLORS = {
|
4
|
-
error: 31,
|
3
|
+
COLORS = {error: 31,
|
5
4
|
attention: 32,
|
6
5
|
prompt: 33,
|
7
|
-
heading:
|
6
|
+
heading: 34}
|
8
7
|
|
9
8
|
def puts_repo_heading(repo)
|
10
|
-
|
9
|
+
puts colorize("\n=== #{repo.name} (#{repo.branch})", COLORS[:heading], true)
|
11
10
|
end
|
12
11
|
|
13
12
|
def puts_heading(text)
|
@@ -27,8 +26,12 @@ module GitBundle
|
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
30
|
-
def colorize(text, color_code)
|
31
|
-
|
29
|
+
def colorize(text, color_code, bold = false)
|
30
|
+
if bold
|
31
|
+
"\e[1m\e[#{color_code}m#{text}\e[0m"
|
32
|
+
else
|
33
|
+
"\e[#{color_code}m#{text}\e[0m"
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -51,15 +51,17 @@ module GitBundle
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def file_changed?(filename)
|
54
|
-
!execute_git("diff --name-only #{filename}").empty?
|
54
|
+
!execute_git("diff --name-only #{filename}").empty? && $?.exitstatus == 0
|
55
55
|
end
|
56
56
|
|
57
57
|
def add_file(filename)
|
58
58
|
execute_git("add #{filename}")
|
59
|
+
$?.exitstatus == 0
|
59
60
|
end
|
60
61
|
|
61
62
|
def commit(message, *files)
|
62
63
|
execute_git("commit -m '#{message}' #{files.join(' ')}")
|
64
|
+
$?.exitstatus == 0
|
63
65
|
end
|
64
66
|
|
65
67
|
def execute_git(command)
|
data/lib/git_bundle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Pretorius
|
@@ -36,14 +36,16 @@ files:
|
|
36
36
|
- ".gitignore"
|
37
37
|
- ".travis.yml"
|
38
38
|
- Gemfile
|
39
|
+
- Gemfile.lock
|
39
40
|
- LICENSE.txt
|
40
41
|
- README.md
|
41
42
|
- bin/gitb
|
42
43
|
- git-bundle.gemspec
|
43
44
|
- lib/git_bundle.rb
|
44
45
|
- lib/git_bundle/cli.rb
|
46
|
+
- lib/git_bundle/commands/generic.rb
|
47
|
+
- lib/git_bundle/commands/push.rb
|
45
48
|
- lib/git_bundle/console.rb
|
46
|
-
- lib/git_bundle/push.rb
|
47
49
|
- lib/git_bundle/repository.rb
|
48
50
|
- lib/git_bundle/version.rb
|
49
51
|
homepage: https://github.com/EPI-USE-Labs/git-bundle
|
data/lib/git_bundle/push.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
module GitBundle
|
2
|
-
class Push
|
3
|
-
include GitBundle::Console
|
4
|
-
|
5
|
-
def initialize(repositories, args)
|
6
|
-
@repositories = repositories
|
7
|
-
@args = args
|
8
|
-
end
|
9
|
-
|
10
|
-
def prompt_confirm
|
11
|
-
commits_to_push = false
|
12
|
-
|
13
|
-
@repositories.each do |repo|
|
14
|
-
commits = repo.commits_not_pushed
|
15
|
-
puts_repo_heading(repo)
|
16
|
-
|
17
|
-
if commits.empty?
|
18
|
-
puts 'No changes.'
|
19
|
-
else
|
20
|
-
commits_to_push = true
|
21
|
-
puts commits
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
if commits_to_push
|
26
|
-
puts_prompt("\nAre you sure you want to push these changes? (Y/N)")
|
27
|
-
STDIN.getch.upcase == 'Y'
|
28
|
-
|
29
|
-
elsif main_repository.file_changed?('Gemfile.lock')
|
30
|
-
puts_prompt("\nAlthough you don't have any commits to push, your Gemfile.lock needs to be rebuilt, committed and pushed.")
|
31
|
-
puts_prompt('Do you want to continue? (Y/N)')
|
32
|
-
STDIN.getch.upcase == 'Y'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def invoke
|
37
|
-
@repositories.each do |repo|
|
38
|
-
if repo.locked_branch != repo.branch
|
39
|
-
puts_error "\nThe git revisions of #{repo.name} does not match. Are you running the correct branch?"
|
40
|
-
puts_error "You are running #{repo.name} branch: #{repo.branch}"
|
41
|
-
puts_error "Gemfile.lock references: #{repo.locked_branch}"
|
42
|
-
return
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
message = @repositories.map { |repo| repo.commit_messages_not_pushed }.uniq.join("\n\n")
|
47
|
-
@repositories.reject { |repo| repo.main || repo.commits_not_pushed.empty? }.each do |repo|
|
48
|
-
puts_repo_heading(repo)
|
49
|
-
unless repo.push(@args)
|
50
|
-
puts_error "Failed to push changes of #{repo.name}. Try pulling the latest changes or resolve conflicts first."
|
51
|
-
return
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
puts_repo_heading(main_repository)
|
56
|
-
repo_changes = @repositories.any? { |repo| repo.revision == repo.locked_revision }
|
57
|
-
|
58
|
-
build_gemfile_lock if repo_changes
|
59
|
-
if main_repository.file_changed?('Gemfile.lock')
|
60
|
-
main_repository.add_file('Gemfile.lock')
|
61
|
-
main_repository.commit("Updated Gemfile.lock to include changes: #{commit_message}", 'Gemfile.lock')
|
62
|
-
end
|
63
|
-
|
64
|
-
main_repository.push(@args)
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
def main_repository
|
69
|
-
@repositories.find { |repo| repo.main }
|
70
|
-
end
|
71
|
-
|
72
|
-
def build_gemfile_lock
|
73
|
-
puts 'Local gems were updated. Building new Gemfile.lock with bundle install.'
|
74
|
-
Dir.chdir(main_repository.path) do
|
75
|
-
puts `bundle install --quiet`
|
76
|
-
$?.exitstatus == 0
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|