git-multirepo 1.0.0.beta1

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +38 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +37 -0
  6. data/LICENSE +22 -0
  7. data/README.md +132 -0
  8. data/Rakefile +2 -0
  9. data/bin/multi +6 -0
  10. data/git-multirepo.gemspec +29 -0
  11. data/lib/commands.rb +11 -0
  12. data/lib/git-multirepo.rb +1 -0
  13. data/lib/info.rb +5 -0
  14. data/lib/multirepo/commands/add.rb +41 -0
  15. data/lib/multirepo/commands/checkout.rb +59 -0
  16. data/lib/multirepo/commands/command.rb +41 -0
  17. data/lib/multirepo/commands/edit.rb +22 -0
  18. data/lib/multirepo/commands/fetch.rb +24 -0
  19. data/lib/multirepo/commands/init.rb +54 -0
  20. data/lib/multirepo/commands/install.rb +61 -0
  21. data/lib/multirepo/commands/open.rb +26 -0
  22. data/lib/multirepo/commands/remove.rb +42 -0
  23. data/lib/multirepo/commands/uninit.rb +21 -0
  24. data/lib/multirepo/commands/update.rb +19 -0
  25. data/lib/multirepo/config.rb +10 -0
  26. data/lib/multirepo/files/config-entry.rb +38 -0
  27. data/lib/multirepo/files/config-file.rb +38 -0
  28. data/lib/multirepo/files/lock-entry.rb +26 -0
  29. data/lib/multirepo/files/lock-file.rb +35 -0
  30. data/lib/multirepo/git/branch.rb +17 -0
  31. data/lib/multirepo/git/change.rb +11 -0
  32. data/lib/multirepo/git/git.rb +33 -0
  33. data/lib/multirepo/git/remote.rb +16 -0
  34. data/lib/multirepo/git/repo.rb +67 -0
  35. data/lib/multirepo/hooks/pre-commit-hook.rb +23 -0
  36. data/lib/multirepo/multirepo-exception.rb +6 -0
  37. data/lib/multirepo/utility/console.rb +52 -0
  38. data/lib/multirepo/utility/runner.rb +21 -0
  39. data/lib/multirepo/utility/utils.rb +37 -0
  40. data/resources/pre-commit +6 -0
  41. data/spec/integration/init-spec.rb +23 -0
  42. data/spec/spec_helper.rb +89 -0
  43. metadata +178 -0
@@ -0,0 +1,11 @@
1
+ module MultiRepo
2
+ class Change
3
+ attr_accessor :status
4
+ attr_accessor :path
5
+
6
+ def initialize(line)
7
+ @status = line[0...2].strip
8
+ @path = line[3..-1]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require "multirepo/utility/runner"
2
+ require "multirepo/git/git"
3
+ require "multirepo/config"
4
+
5
+ module MultiRepo
6
+ class Git
7
+ class << self
8
+ attr_accessor :last_command_succeeded
9
+ end
10
+
11
+ def self.run_in_current_dir(git_command, show_output)
12
+ full_command = "git #{git_command}"
13
+ run(full_command, show_output)
14
+ end
15
+
16
+ def self.run_in_working_dir(path, git_command, show_output)
17
+ full_command = "git -C \"#{path}\" #{git_command}";
18
+ run(full_command, show_output)
19
+ end
20
+
21
+ def self.run(full_command, show_output)
22
+ Console.log_info(full_command) if Config.instance.verbose
23
+ result = Runner.run(full_command, show_output)
24
+ @last_command_succeeded = Runner.last_command_succeeded
25
+ return result
26
+ end
27
+
28
+ def self.is_inside_git_repo(path)
29
+ Dir.exist?("#{path}/.git")
30
+ #return (Git.run_in_working_dir(path, "rev-parse --is-inside-work-tree", false).strip == "true") # Can't silence output?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "git"
2
+
3
+ module MultiRepo
4
+ class Remote
5
+ attr_accessor :name
6
+
7
+ def initialize(repo, name)
8
+ @repo = repo
9
+ @name = name
10
+ end
11
+
12
+ def url
13
+ Git.run_in_working_dir(@repo.path, "config --get remote.#{@name}.url", false).strip
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,67 @@
1
+ require_relative "branch"
2
+ require_relative "remote"
3
+ require_relative "change"
4
+
5
+ module MultiRepo
6
+ class Repo
7
+ attr_accessor :path
8
+ attr_accessor :basename
9
+
10
+ def initialize(path)
11
+ @path = path
12
+ @basename = Pathname.new(path).basename.to_s
13
+ end
14
+
15
+ # Inspection
16
+
17
+ def exists?
18
+ Git.is_inside_git_repo(@path)
19
+ end
20
+
21
+ def current_branch
22
+ branch = Git.run_in_working_dir(@path, "rev-parse --abbrev-ref HEAD", false).strip
23
+ branch != "HEAD" ? branch : nil
24
+ end
25
+
26
+ def head_hash
27
+ Git.run_in_working_dir(@path, "rev-parse HEAD", false).strip
28
+ end
29
+
30
+ def changes
31
+ output = Git.run_in_working_dir(@path, "status --porcelain", false)
32
+ lines = output.split("\n").each{ |f| f.strip }.delete_if{ |f| f == "" }
33
+ lines.map { |l| Change.new(l) }
34
+ end
35
+
36
+ def is_clean?
37
+ return changes.count == 0
38
+ end
39
+
40
+ # Operations
41
+
42
+ def fetch
43
+ Git.run_in_working_dir(@path, "fetch --progress", true)
44
+ Runner.last_command_succeeded
45
+ end
46
+
47
+ def clone(url)
48
+ Git.run_in_current_dir("clone #{url} #{@path} --progress", true)
49
+ Runner.last_command_succeeded
50
+ end
51
+
52
+ def checkout(ref)
53
+ Git.run_in_working_dir(@path, "checkout #{ref}", false)
54
+ Runner.last_command_succeeded
55
+ end
56
+
57
+ # Remotes and branches
58
+
59
+ def branch(name)
60
+ Branch.new(self, name)
61
+ end
62
+
63
+ def remote(name)
64
+ Remote.new(self, name)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ require "multirepo/files/config-file"
2
+ require "multirepo/files/lock-file"
3
+ require "multirepo/utility/utils"
4
+ require "multirepo/utility/console"
5
+
6
+ module MultiRepo
7
+ class PreCommitHook
8
+ def self.run
9
+ entries = ConfigFile.load
10
+ uncommitted = Utils.warn_of_uncommitted_changes(entries)
11
+
12
+ if uncommitted
13
+ Console.log_error("You must commit changes to your dependencies before you can commit the main repo")
14
+ exit 1
15
+ end
16
+
17
+ LockFile.update
18
+ Console.log_info("Updated and staged lock file with current HEAD revisions for all dependencies")
19
+
20
+ exit 0 # Success!
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require "claide/informative_error"
2
+
3
+ module MultiRepo
4
+ class MultiRepoException < StandardError
5
+ end
6
+ end
@@ -0,0 +1,52 @@
1
+ require "colored"
2
+
3
+ module MultiRepo
4
+ class Console
5
+ def self.log_step(message)
6
+ print_arrow
7
+ puts $stdout.isatty ? message.bold.green : message
8
+ end
9
+
10
+ def self.log_substep(message)
11
+ print_arrow
12
+ puts $stdout.isatty ? message.blue : message
13
+ end
14
+
15
+ def self.log_info(message)
16
+ print_arrow
17
+ puts $stdout.isatty ? message.white : message
18
+ end
19
+
20
+ def self.log_warning(message)
21
+ print_arrow
22
+ puts $stdout.isatty ? message.yellow : message
23
+ end
24
+
25
+ def self.log_error(message)
26
+ print_arrow
27
+ puts $stdout.isatty ? message.red : message
28
+ end
29
+
30
+ def self.ask_yes_no(message)
31
+ answered = false
32
+ while !answered
33
+ print_arrow
34
+ print message
35
+ print " (y/n) "
36
+
37
+ case $stdin.gets.strip.downcase
38
+ when "y", "yes"
39
+ answered = true
40
+ return true
41
+ when "n", "no"
42
+ answered = true
43
+ return false
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.print_arrow
49
+ print $stdout.isatty ? "> ".white : ""
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,21 @@
1
+ require "open3"
2
+
3
+ module MultiRepo
4
+ class Runner
5
+ class << self
6
+ attr_accessor :last_command_succeeded
7
+ end
8
+
9
+ def self.run(cmd, show_output)
10
+ output = []
11
+ Open3.popen2e(cmd) do |stdin, stdout_and_stderr, thread|
12
+ stdout_and_stderr.each do |line|
13
+ puts line if show_output
14
+ output << line
15
+ end
16
+ @last_command_succeeded = thread.value.success?
17
+ end
18
+ output.join("")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ require "fileutils"
2
+
3
+ module MultiRepo
4
+ class Utils
5
+ def self.path_for_resource(resource_name)
6
+ gem_path = Gem::Specification.find_by_name("git-multirepo").gem_dir
7
+ File.join(gem_path, "resources/#{resource_name}")
8
+ end
9
+
10
+ def self.install_pre_commit_hook
11
+ FileUtils.cp(path_for_resource("pre-commit"), ".git/hooks")
12
+ end
13
+
14
+ def self.sibling_repos
15
+ sibling_directories = Dir['../*/']
16
+ sibling_repos = sibling_directories.map{ |d| Repo.new(d) }.select{ |r| r.exists? }
17
+ sibling_repos.delete_if{ |r| Pathname.new(r.path).realpath == Pathname.new(".").realpath }
18
+ end
19
+
20
+ def self.warn_of_uncommitted_changes(config_entries)
21
+ uncommitted = false
22
+ config_entries.each do |e|
23
+ next unless e.repo.exists?
24
+ unless e.repo.is_clean?
25
+ Console.log_warning("Dependency '#{e.repo.path}' contains uncommitted changes")
26
+ uncommitted = true
27
+ end
28
+ end
29
+ return uncommitted
30
+ end
31
+
32
+ def self.convert_to_windows_path(unix_path)
33
+ components = Pathname.new(unix_path).each_filename.to_a
34
+ components.join(File::ALT_SEPARATOR)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "git-multirepo"
5
+
6
+ MultiRepo::PreCommitHook.run
@@ -0,0 +1,23 @@
1
+ require "multirepo/commands/init"
2
+
3
+ RSpec.describe("Init") do
4
+ it "creates the config file" do
5
+ pending
6
+ end
7
+
8
+ it "adds only specified repos to the config file" do
9
+ pending
10
+ end
11
+
12
+ it "stages the config file" do
13
+ pending
14
+ end
15
+
16
+ it "installs the pre-commit hook" do
17
+ pending
18
+ end
19
+
20
+ it "fails when there are uncommitted changes in dependencies" do
21
+ pending
22
+ end
23
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-multirepo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Michaël Fortin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-03 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: claide
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 0.8.0
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: '0.8'
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: 0.8.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: colored
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '1.2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '1.2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: os
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 0.9.6
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.6
103
+ description: Track multiple Git repositories side-by-side.
104
+ email:
105
+ - fortinmike@irradiated.net
106
+ executables:
107
+ - multi
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - .gitignore
112
+ - .rspec
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - LICENSE
116
+ - README.md
117
+ - Rakefile
118
+ - bin/multi
119
+ - git-multirepo.gemspec
120
+ - lib/commands.rb
121
+ - lib/git-multirepo.rb
122
+ - lib/info.rb
123
+ - lib/multirepo/commands/add.rb
124
+ - lib/multirepo/commands/checkout.rb
125
+ - lib/multirepo/commands/command.rb
126
+ - lib/multirepo/commands/edit.rb
127
+ - lib/multirepo/commands/fetch.rb
128
+ - lib/multirepo/commands/init.rb
129
+ - lib/multirepo/commands/install.rb
130
+ - lib/multirepo/commands/open.rb
131
+ - lib/multirepo/commands/remove.rb
132
+ - lib/multirepo/commands/uninit.rb
133
+ - lib/multirepo/commands/update.rb
134
+ - lib/multirepo/config.rb
135
+ - lib/multirepo/files/config-entry.rb
136
+ - lib/multirepo/files/config-file.rb
137
+ - lib/multirepo/files/lock-entry.rb
138
+ - lib/multirepo/files/lock-file.rb
139
+ - lib/multirepo/git/branch.rb
140
+ - lib/multirepo/git/change.rb
141
+ - lib/multirepo/git/git.rb
142
+ - lib/multirepo/git/remote.rb
143
+ - lib/multirepo/git/repo.rb
144
+ - lib/multirepo/hooks/pre-commit-hook.rb
145
+ - lib/multirepo/multirepo-exception.rb
146
+ - lib/multirepo/utility/console.rb
147
+ - lib/multirepo/utility/runner.rb
148
+ - lib/multirepo/utility/utils.rb
149
+ - resources/pre-commit
150
+ - spec/integration/init-spec.rb
151
+ - spec/spec_helper.rb
152
+ homepage: http://www.irradiated.net
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ~>
163
+ - !ruby/object:Gem::Version
164
+ version: '2.0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>'
168
+ - !ruby/object:Gem::Version
169
+ version: 1.3.1
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.0.14
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Track multiple Git repositories side-by-side
176
+ test_files:
177
+ - spec/integration/init-spec.rb
178
+ - spec/spec_helper.rb