git-bundle 1.0.0
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 +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/bin/gitb +7 -0
- data/git-bundle.gemspec +22 -0
- data/lib/git_bundle.rb +6 -0
- data/lib/git_bundle/cli.rb +53 -0
- data/lib/git_bundle/console.rb +34 -0
- data/lib/git_bundle/push.rb +80 -0
- data/lib/git_bundle/repository.rb +72 -0
- data/lib/git_bundle/version.rb +3 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0dd685911b226352aa32543af4105bae31803a7e
|
4
|
+
data.tar.gz: 398ca4bd1490964051abf510a06ad09eb94707c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01b515763ab53d4e7b7daa3b99be699e65a990881cdba28787fbffa29dd75af8bc6b94363c926a6a8e317aa172f72118640b12817b8b66bbc2b7deb994989e45
|
7
|
+
data.tar.gz: 5158116901d34f851a00a376b412ebe71ee0e8765b9b4fbe746f38217684ada7dfb2a3cceab3717f22bbcef81d9c207e49f0f65e9ab4a4513b427783566bc08e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Pierre Pretorius
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Git::Bundle
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/git/bundle`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'git-bundle'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install git-bundle
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git-bundle.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/bin/gitb
ADDED
data/git-bundle.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git_bundle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'git-bundle'
|
8
|
+
spec.version = GitBundle::VERSION
|
9
|
+
spec.authors = ['Pierre Pretorius']
|
10
|
+
spec.email = ['pierre@labs.epiuse.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Makes life easier when working with git and local overrides of bundled gems.}
|
13
|
+
spec.description = %q{If you are using Bundler and local overrides of gems or Rails engines this gem might be for you.}
|
14
|
+
spec.homepage = 'https://github.com/EPI-USE-Labs/git-bundle'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = 'gitb'
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
22
|
+
end
|
data/lib/git_bundle.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module GitBundle
|
2
|
+
class CLI
|
3
|
+
include GitBundle::Console
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@errors = []
|
7
|
+
load_repositories
|
8
|
+
end
|
9
|
+
|
10
|
+
def invoke(args)
|
11
|
+
case args[0]
|
12
|
+
when nil, '--help', 'help'
|
13
|
+
puts `git #{args.join(' ')}`.gsub('git', 'gitb')
|
14
|
+
when 'push'
|
15
|
+
push = GitBundle::Push.new(@repositories, args[1..-1])
|
16
|
+
push.invoke if push.prompt_confirm
|
17
|
+
else
|
18
|
+
exec_all(args)
|
19
|
+
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
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def load_repositories
|
37
|
+
@repositories = []
|
38
|
+
begin
|
39
|
+
lockfile_content = Bundler.read_file(Bundler.default_lockfile)
|
40
|
+
all_specs = Bundler::LockfileParser.new(lockfile_content).specs
|
41
|
+
Bundler.settings.local_overrides.each do |name, path|
|
42
|
+
spec = all_specs.find { |s| s.name == name }
|
43
|
+
@repositories << GitBundle::Repository.new_dependant(spec.name, path, spec.source.branch, spec.source.revision) if spec
|
44
|
+
end
|
45
|
+
|
46
|
+
rescue Bundler::LockfileError
|
47
|
+
@errors << "Error reading #{Bundler.default_lockfile}: \n\t#{error.message}."
|
48
|
+
end
|
49
|
+
|
50
|
+
@repositories << GitBundle::Repository.new_main(File.basename(Dir.getwd), Dir.getwd)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module GitBundle
|
2
|
+
module Console
|
3
|
+
COLORS = {std: 0,
|
4
|
+
error: 31,
|
5
|
+
attention: 32,
|
6
|
+
prompt: 33,
|
7
|
+
heading: 36}
|
8
|
+
|
9
|
+
def puts_repo_heading(repo)
|
10
|
+
puts_heading "#{repo.name} (#{repo.branch})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def puts_heading(text)
|
14
|
+
puts colorize("\n=== #{text}", COLORS[:heading])
|
15
|
+
end
|
16
|
+
|
17
|
+
def puts_attention(text)
|
18
|
+
puts colorize(text, COLORS[:attention])
|
19
|
+
end
|
20
|
+
|
21
|
+
def puts_prompt(text)
|
22
|
+
puts colorize(text, COLORS[:prompt])
|
23
|
+
end
|
24
|
+
|
25
|
+
def puts_error(text)
|
26
|
+
puts colorize(text, COLORS[:error])
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def colorize(text, color_code)
|
31
|
+
"\e[#{color_code}m#{text}\e[0m"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,80 @@
|
|
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
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module GitBundle
|
2
|
+
class Repository
|
3
|
+
attr_reader :name,
|
4
|
+
:path,
|
5
|
+
:main
|
6
|
+
|
7
|
+
def self.new_main(name, path)
|
8
|
+
GitBundle::Repository.new(name, path, true, nil, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.new_dependant(name, path, locked_branch, locked_revision)
|
12
|
+
GitBundle::Repository.new(name, path, false, locked_branch, locked_revision)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(name, path, main_repository, locked_branch, locked_revision)
|
16
|
+
@name = name
|
17
|
+
@path = path
|
18
|
+
@main = main_repository
|
19
|
+
@locked_branch = locked_branch
|
20
|
+
@locked_revision = locked_revision
|
21
|
+
end
|
22
|
+
|
23
|
+
def branch
|
24
|
+
@branch ||= execute_git('rev-parse --abbrev-ref HEAD')
|
25
|
+
end
|
26
|
+
|
27
|
+
def locked_branch
|
28
|
+
@locked_branch || branch
|
29
|
+
end
|
30
|
+
|
31
|
+
def revision
|
32
|
+
@revision ||= execute_git('rev-parse --verify HEAD').gsub("\n", '')
|
33
|
+
end
|
34
|
+
|
35
|
+
def locked_revision
|
36
|
+
@locked_revision || revision
|
37
|
+
end
|
38
|
+
|
39
|
+
def commits_not_pushed
|
40
|
+
execute_git("log #{branch} --not --remotes")
|
41
|
+
end
|
42
|
+
|
43
|
+
def commit_messages_not_pushed
|
44
|
+
count = execute_git("rev-list #{branch} --count --not --remotes").to_i
|
45
|
+
count.times.map { |num| execute_git("log #{branch} --not --remotes --skip=#{num} --max-count=1 --pretty=format:'%B'").strip }
|
46
|
+
end
|
47
|
+
|
48
|
+
def push(args)
|
49
|
+
puts execute_git("push #{args.join(' ')}")
|
50
|
+
$?.exitstatus == 0
|
51
|
+
end
|
52
|
+
|
53
|
+
def file_changed?(filename)
|
54
|
+
!execute_git("diff --name-only #{filename}").empty?
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_file(filename)
|
58
|
+
execute_git("add #{filename}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def commit(message, *files)
|
62
|
+
execute_git("commit -m '#{message}' #{files.join(' ')}")
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def execute_git(command)
|
67
|
+
full_command = "git -C #{@path} #{command}"
|
68
|
+
puts full_command if ENV['DEBUG'] == 'true'
|
69
|
+
`#{full_command}`.strip
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-bundle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pierre Pretorius
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
description: If you are using Bundler and local overrides of gems or Rails engines
|
28
|
+
this gem might be for you.
|
29
|
+
email:
|
30
|
+
- pierre@labs.epiuse.com
|
31
|
+
executables:
|
32
|
+
- gitb
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- ".travis.yml"
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- bin/gitb
|
42
|
+
- git-bundle.gemspec
|
43
|
+
- lib/git_bundle.rb
|
44
|
+
- lib/git_bundle/cli.rb
|
45
|
+
- lib/git_bundle/console.rb
|
46
|
+
- lib/git_bundle/push.rb
|
47
|
+
- lib/git_bundle/repository.rb
|
48
|
+
- lib/git_bundle/version.rb
|
49
|
+
homepage: https://github.com/EPI-USE-Labs/git-bundle
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.5.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Makes life easier when working with git and local overrides of bundled gems.
|
73
|
+
test_files: []
|