brigit 0.8.2 → 0.9.1

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.
data/Manifest CHANGED
@@ -1,7 +1,12 @@
1
1
  bin/brigit
2
+ help/grab.rdoc
3
+ help/hop.rdoc
4
+ help/map.rdoc
5
+ help/update.rdoc
2
6
  lib/brigit/cli.rb
3
7
  lib/brigit/commands/command.rb
4
8
  lib/brigit/commands/grab_command.rb
9
+ lib/brigit/commands/hop_command.rb
5
10
  lib/brigit/commands/map_command.rb
6
11
  lib/brigit/commands/update_command.rb
7
12
  lib/brigit/config_parser.rb
@@ -9,12 +14,24 @@ lib/brigit/fallible.rb
9
14
  lib/brigit/inventories/gitosis_inventory.rb
10
15
  lib/brigit/inventories/inventory.rb
11
16
  lib/brigit/listable.rb
17
+ lib/brigit/pretending.rb
12
18
  lib/brigit/version.rb
13
19
  lib/brigit.rb
14
20
  lib/ext/option_parser.rb
15
21
  Manifest
16
22
  Rakefile
17
23
  README.rdoc
24
+ test/brigit_test.rb
25
+ test/cli_test.rb
26
+ test/command_test.rb
18
27
  test/config_parser_test.rb
28
+ test/fallible_test.rb
19
29
  test/fixtures/example.conf
30
+ test/fixtures/gitosis-admin/gitosis.conf
31
+ test/fixtures/grab_command/existing_directory/stub
32
+ test/fixtures/submodule_methods/parent/submodule/foo.rb
33
+ test/gitosis_test.rb
34
+ test/grab_command_test.rb
35
+ test/inventory_test.rb
36
+ test/option_parser_test.rb
20
37
  test/test_helper.rb
data/README.rdoc CHANGED
@@ -6,6 +6,15 @@ A random collection of utilities for developers working with Git repositories.
6
6
 
7
7
  Feel free to fork, send patches, etc. Development is done at http://github.com/fiveruns/brigit
8
8
 
9
+ == Usage
10
+
11
+ Call the +brigit+ executable without any arguments to get the list of commands;
12
+ you can then do:
13
+
14
+ brigit <command> --help
15
+
16
+ The same information is available under the help/.
17
+
9
18
  == Authors
10
19
 
11
20
  The FiveRuns development team, http://www.fiveruns.org
data/Rakefile CHANGED
@@ -11,5 +11,5 @@ Echoe.new 'brigit' do |p|
11
11
  p.summary = "Git utilities"
12
12
  p.url = "http://github.com/fiveruns/brigit"
13
13
  p.include_rakefile = true
14
- end
15
-
14
+ p.rcov_options << '--sort coverage --exclude gems --text-summary'
15
+ end
data/bin/brigit CHANGED
@@ -2,7 +2,5 @@
2
2
 
3
3
  require File.dirname(__FILE__) << "/../lib/brigit"
4
4
 
5
- Brigit::CLI.new.parse(*ARGV) do |command|
6
- command.execute!
7
- end
5
+ Brigit::CLI.new.parse(*ARGV).run
8
6
 
data/brigit.gemspec CHANGED
@@ -1,55 +1,131 @@
1
1
 
2
- # Gem::Specification for Brigit-0.8.2
2
+ # Gem::Specification for Brigit-0.9.1
3
3
  # Originally generated by Echoe
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = %q{brigit}
7
- s.version = "0.8.2"
5
+ --- !ruby/object:Gem::Specification
6
+ name: brigit
7
+ version: !ruby/object:Gem::Version
8
+ version: 0.9.1
9
+ platform: ruby
10
+ authors:
11
+ - FiveRuns Development Team
12
+ autorequire:
13
+ bindir: bin
8
14
 
9
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
- s.authors = ["FiveRuns Development Team"]
11
- s.date = %q{2008-07-08}
12
- s.default_executable = %q{brigit}
13
- s.description = %q{Git utilities}
14
- s.email = %q{dev@fiveruns.com}
15
- s.executables = ["brigit"]
16
- s.extra_rdoc_files = ["bin/brigit", "lib/brigit/cli.rb", "lib/brigit/commands/command.rb", "lib/brigit/commands/grab_command.rb", "lib/brigit/commands/map_command.rb", "lib/brigit/commands/update_command.rb", "lib/brigit/config_parser.rb", "lib/brigit/fallible.rb", "lib/brigit/inventories/gitosis_inventory.rb", "lib/brigit/inventories/inventory.rb", "lib/brigit/listable.rb", "lib/brigit/version.rb", "lib/brigit.rb", "lib/ext/option_parser.rb", "README.rdoc"]
17
- s.files = ["bin/brigit", "lib/brigit/cli.rb", "lib/brigit/commands/command.rb", "lib/brigit/commands/grab_command.rb", "lib/brigit/commands/map_command.rb", "lib/brigit/commands/update_command.rb", "lib/brigit/config_parser.rb", "lib/brigit/fallible.rb", "lib/brigit/inventories/gitosis_inventory.rb", "lib/brigit/inventories/inventory.rb", "lib/brigit/listable.rb", "lib/brigit/version.rb", "lib/brigit.rb", "lib/ext/option_parser.rb", "Manifest", "Rakefile", "README.rdoc", "test/config_parser_test.rb", "test/fixtures/example.conf", "test/test_helper.rb", "brigit.gemspec"]
18
- s.has_rdoc = true
19
- s.homepage = %q{http://github.com/fiveruns/brigit}
20
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Brigit", "--main", "README.rdoc"]
21
- s.require_paths = ["lib"]
22
- s.rubyforge_project = %q{fiveruns}
23
- s.rubygems_version = %q{1.2.0}
24
- s.summary = %q{Git utilities}
25
- s.test_files = ["test/config_parser_test.rb", "test/test_helper.rb"]
15
+ date: 2008-07-12 00:00:00 -05:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: echoe
20
+ type: :development
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ version:
28
+ description: Git utilities
29
+ email: dev@fiveruns.com
30
+ executables:
31
+ - brigit
32
+ extensions: []
26
33
 
27
- if s.respond_to? :specification_version then
28
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
- s.specification_version = 2
34
+ extra_rdoc_files:
35
+ - bin/brigit
36
+ - lib/brigit/cli.rb
37
+ - lib/brigit/commands/command.rb
38
+ - lib/brigit/commands/grab_command.rb
39
+ - lib/brigit/commands/hop_command.rb
40
+ - lib/brigit/commands/map_command.rb
41
+ - lib/brigit/commands/update_command.rb
42
+ - lib/brigit/config_parser.rb
43
+ - lib/brigit/fallible.rb
44
+ - lib/brigit/inventories/gitosis_inventory.rb
45
+ - lib/brigit/inventories/inventory.rb
46
+ - lib/brigit/listable.rb
47
+ - lib/brigit/pretending.rb
48
+ - lib/brigit/version.rb
49
+ - lib/brigit.rb
50
+ - lib/ext/option_parser.rb
51
+ - README.rdoc
52
+ files:
53
+ - bin/brigit
54
+ - help/grab.rdoc
55
+ - help/hop.rdoc
56
+ - help/map.rdoc
57
+ - help/update.rdoc
58
+ - lib/brigit/cli.rb
59
+ - lib/brigit/commands/command.rb
60
+ - lib/brigit/commands/grab_command.rb
61
+ - lib/brigit/commands/hop_command.rb
62
+ - lib/brigit/commands/map_command.rb
63
+ - lib/brigit/commands/update_command.rb
64
+ - lib/brigit/config_parser.rb
65
+ - lib/brigit/fallible.rb
66
+ - lib/brigit/inventories/gitosis_inventory.rb
67
+ - lib/brigit/inventories/inventory.rb
68
+ - lib/brigit/listable.rb
69
+ - lib/brigit/pretending.rb
70
+ - lib/brigit/version.rb
71
+ - lib/brigit.rb
72
+ - lib/ext/option_parser.rb
73
+ - Manifest
74
+ - Rakefile
75
+ - README.rdoc
76
+ - test/brigit_test.rb
77
+ - test/cli_test.rb
78
+ - test/command_test.rb
79
+ - test/config_parser_test.rb
80
+ - test/fallible_test.rb
81
+ - test/fixtures/example.conf
82
+ - test/fixtures/gitosis-admin/gitosis.conf
83
+ - test/fixtures/grab_command/existing_directory/stub
84
+ - test/fixtures/submodule_methods/parent/submodule/foo.rb
85
+ - test/gitosis_test.rb
86
+ - test/grab_command_test.rb
87
+ - test/inventory_test.rb
88
+ - test/option_parser_test.rb
89
+ - test/test_helper.rb
90
+ - brigit.gemspec
91
+ has_rdoc: true
92
+ homepage: http://github.com/fiveruns/brigit
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --line-numbers
96
+ - --inline-source
97
+ - --title
98
+ - Brigit
99
+ - --main
100
+ - README.rdoc
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ version:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "="
112
+ - !ruby/object:Gem::Version
113
+ version: "1.2"
114
+ version:
115
+ requirements: []
30
116
 
31
- if current_version >= 3 then
32
- else
33
- end
34
- else
35
- end
36
- end
37
-
38
-
39
- # # Original Rakefile source (requires the Echoe gem):
40
- #
41
- # require 'rubygems'
42
- # require 'echoe'
43
- #
44
- # require File.dirname(__FILE__) << "/lib/brigit/version"
45
- #
46
- # Echoe.new 'brigit' do |p|
47
- # p.version = Brigit::Version::STRING
48
- # p.author = "FiveRuns Development Team"
49
- # p.email = 'dev@fiveruns.com'
50
- # p.project = 'fiveruns'
51
- # p.summary = "Git utilities"
52
- # p.url = "http://github.com/fiveruns/brigit"
53
- # p.include_rakefile = true
54
- # end
55
- #
117
+ rubyforge_project: fiveruns
118
+ rubygems_version: 1.2.0
119
+ specification_version: 2
120
+ summary: Git utilities
121
+ test_files:
122
+ - test/brigit_test.rb
123
+ - test/cli_test.rb
124
+ - test/command_test.rb
125
+ - test/config_parser_test.rb
126
+ - test/fallible_test.rb
127
+ - test/gitosis_test.rb
128
+ - test/grab_command_test.rb
129
+ - test/inventory_test.rb
130
+ - test/option_parser_test.rb
131
+ - test/test_helper.rb
data/help/grab.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ Grab repos matching optional pattern from a gitosis-admin config"
2
+
3
+ == Syntax
4
+
5
+ brigit grab PATH_TO_GITOSIS_ADMIN_REPO [PATTERN, ...]
6
+
7
+ == Examples
8
+
9
+ Using the list of repositories provided by ~/gitosis-admin, clone all that
10
+ include the substring 'my-product' or 'their-product'
11
+
12
+ brigit grab ~/gitosis-admin my-product their-product
13
+
14
+ The same, but clone all repositories:
15
+
16
+ brigit grab ~/gitosis-admin
data/help/hop.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ Change submodule references in repositories.
2
+
3
+ == Syntax
4
+
5
+ brigit hop SUBMODULE_URL [OPTIONS] [REPO_PATHS, ...]
6
+
7
+ == Notes
8
+
9
+ * For safety reasons:
10
+ * It WILL NOT change a submodule that has uncommitted changes; the
11
+ submodule must be pristine. You need to handle these submodules manually.
12
+ * It does not currently commit the updated submodule reference in the parent
13
+ repository; the list of modified repos are output after the command
14
+ is executed; you still need to commit and push manually.
15
+ * It will do a fresh pull from the submodule's origin before checking out the
16
+ reference you select with the -r/--ref option (default: 'master')
17
+
18
+ == Examples
19
+
20
+ Update all submodules pointing to remote origin 'git@example.com:mine' in
21
+ repositories under PWD (or just PWD, if it's a repo itself) to a whatever
22
+ the current commit is on the 'master' branch.
23
+
24
+ git hop git@example.com:mine
25
+
26
+ Do the same, but only in the foo/bar repository
27
+
28
+ git hop git@example.com:mine foo/bar
29
+
30
+ The same, but this time set the submodule commit to the 'alternate' branch
31
+
32
+ git hop git@example.com:mine -r alternate foo/bar
33
+
34
+ And this time, commit SHA 25b306c73
35
+
36
+ git hop git@example.com:mine -r 25b306c73 foo/bar
data/help/map.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ Graphs of submodules in this repository
2
+
3
+ == Syntax
4
+
5
+ brigit map [OPTIONS]
6
+
7
+ == Notes
8
+
9
+ You must be in the Git repository when this command is executed.
10
+
11
+ == Examples
12
+
13
+ Output DOT-format output for current repository structure:
14
+
15
+ brigit map
16
+
17
+ Display graph of current repository structure:
18
+
19
+ brigit map -o
data/help/update.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ Update all submodules in the repo, recursively
2
+
3
+ == Syntax
4
+
5
+ brigit update
6
+
7
+ == Notes
8
+
9
+ You must be in the Git repository when this command is executed.
data/lib/brigit/cli.rb CHANGED
@@ -5,55 +5,24 @@ module Brigit
5
5
  class CLI
6
6
 
7
7
  def parse(*args)
8
- self.class.parser.parse!(args)
9
- if (args.first && command = Command[args.shift])
10
- yield command.new(self.class.options, *args)
8
+ if (command = Command[args.shift])
9
+ command.new(*args)
11
10
  else
12
- abort "No command given.\n#{parser}"
11
+ abort "No command given.\n\n#{self.class.usage}"
13
12
  end
14
13
  end
15
-
16
- def self.usage
17
- parser.to_s
18
- end
19
-
20
- #######
21
- private
22
- #######
23
14
 
24
- def self.options
25
- @options ||= OpenStruct.new
15
+ def self.banner
16
+ %{Brigit (v#{Version::STRING}) Submodule utilities for Git}
26
17
  end
27
-
28
- def self.parser
29
-
30
- command_list = Command.list.map { |command| " * #{command.name}: #{command.help}" }.join("\n")
31
-
32
- options.inventory = {}
33
-
34
- @parser ||= OptionParser.new do |opts|
35
-
36
- opts.banner = %("Brigit," Submodule utilities for Git\nUSAGE: brigit COMMAND [OPTIONS])
37
-
38
- opts.separator "COMMANDS:\n#{command_list}\n"
39
18
 
40
- opts.separator "OPTIONS:\n"
41
-
42
- Inventory.list.each do |inventory|
43
- opts.on("-#{inventory.name[0,1]}", "--#{inventory.name} PATH", "Location of #{inventory.name} (`grab' only)") do |path|
44
- options.inventory[inventory] = path
45
- end
46
- end
47
-
48
- opts.on('-o', '--open', "Open with Preview.app (`map' only, requires OSX & `dot' in PATH)") do
49
- options.open = true
50
- end
51
-
52
- opts.on_tail('-h', '--help', 'Show this message') do
53
- abort opts.to_s
54
- end
55
-
56
- end
19
+ def self.usage
20
+ lines = [
21
+ banner,
22
+ %{COMMANDS: (`COMMAND --help' for documentation)},
23
+ *Command.list.map { |cmd| " #{cmd.name}" }.sort
24
+ ]
25
+ lines.join "\n"
57
26
  end
58
27
 
59
28
  end
@@ -1,29 +1,65 @@
1
1
  require 'brigit/listable'
2
2
  require 'brigit/fallible'
3
+ require 'brigit/pretending'
4
+
3
5
 
4
6
  module Brigit
5
7
 
6
8
  class Command
7
9
  include Listable
8
10
  include Fallible
11
+ include Pretending
9
12
 
10
- class << self
11
- attr_accessor :help
13
+ def self.help
14
+ @help ||= begin
15
+ help_file = File.dirname(__FILE__) << "/../../../help/#{name}.rdoc"
16
+ if File.file?(help_file)
17
+ File.read(help_file)
18
+ else
19
+ "Sorry, there is no documentation for this command."
20
+ end
21
+ end
12
22
  end
13
23
 
14
- attr_reader :options, :args
15
- def initialize(options, *args)
16
- @options = options
24
+ attr_reader :args
25
+ def initialize(*args)
17
26
  @args = args
18
27
  end
19
28
 
20
- def execute!
21
- raise ArgumentError, "Must be in Git repository" unless repo?
29
+ def run
30
+ yield parser if block_given?
31
+ parser.parse!(args)
22
32
  end
23
33
 
24
34
  #######
25
35
  private
26
36
  #######
37
+
38
+ def say(message)
39
+ message = pretending? ? "{PRETENDING} #{message}" : message
40
+ $stderr.puts message
41
+ end
42
+
43
+ def sh(command)
44
+ if pretending?
45
+ say command
46
+ else
47
+ system command
48
+ end
49
+ end
50
+
51
+ def check_repo!
52
+ raise ArgumentError, "Must be in Git repository" unless repo?
53
+ end
54
+
55
+ def parser
56
+ @parser ||= OptionParser.new do |opts|
57
+ opts.banner = CLI.banner + "\n---\n= Help on the `#{self.class.name}' command\n\n" + self.class.help + "\n\n== Options\n"
58
+ opts.on_tail('-h', '--help', 'Show this message') do
59
+ abort opts.to_s
60
+ end
61
+ end
62
+ end
27
63
 
28
64
  def repo?
29
65
  File.directory?(File.join(Dir.pwd, '.git'))
@@ -5,20 +5,16 @@ module Brigit
5
5
 
6
6
  class GrabCommand < Command
7
7
 
8
- self.help = "Grab repos matching optional pattern from a gitosis-admin config"
9
-
10
- def execute!
11
- validate!
8
+ def run
9
+ super { |parser| add_pretend_to parser }
12
10
  matching_repositories.each do |name, location|
13
11
  if File.exists?(name)
14
- STDERR.puts "#{name}: Already exists, skipping..."
12
+ say "#{name}: Already exists, skipping..."
15
13
  else
16
- STDERR.puts "#{name}: Cloning from #{location} ..."
17
- system "git clone '#{location}' '#{name}'"
18
- STDERR.puts "#{name}: Updating submodules ..."
19
- Dir.chdir name do
20
- updater.execute!
21
- end
14
+ say "#{name}: Cloning from #{location} ..."
15
+ sh "git clone '#{location}' '#{name}'"
16
+ say "#{name}: Updating submodules ..."
17
+ update name
22
18
  end
23
19
  end
24
20
  end
@@ -27,22 +23,26 @@ module Brigit
27
23
  private
28
24
  #######
29
25
 
30
- def updater
31
- @updater ||= UpdateCommand.new(options)
26
+ def update(name)
27
+ if pretending?
28
+ say "(Would update submodules for `#{name}')"
29
+ else
30
+ if File.directory?(name)
31
+ Dir.chdir name do
32
+ UpdateCommand.new.run
33
+ end
34
+ else
35
+ say "ERROR: Directory #{name} was not created; skipping..."
36
+ end
37
+ end
32
38
  end
33
-
34
- def validate!
35
- if options.inventory.empty?
36
- list = Inventory.listing { |name| "--#{name}" }
37
- fail "Can't find list of repositories; need to set #{list}"
38
- end
39
+
40
+ def inventory
41
+ @inventory ||= GitosisInventory.new(args.shift)
39
42
  end
40
43
 
41
44
  def all_repositories
42
- options.inventory.inject({}) do |all, (klass, path)|
43
- source = klass.new(path)
44
- all.merge(source.repositories)
45
- end
45
+ inventory.repositories
46
46
  end
47
47
 
48
48
  def matching_repositories
@@ -0,0 +1,91 @@
1
+ require 'brigit/commands/command'
2
+
3
+ module Brigit
4
+
5
+ class HopCommand < Command
6
+
7
+ def run
8
+ ref = default_ref
9
+ super do |parser|
10
+ parser.on('-r TREE-ISH', '--ref', "(default: `#{ref}')") do |treeish|
11
+ ref = treeish
12
+ end
13
+ add_pretend_to parser
14
+ end
15
+ check_url!
16
+ changed = []
17
+ errors = []
18
+ submodules.each do |path, parent|
19
+ Dir.chdir path do
20
+ say "cd #{path}"
21
+ if clean?
22
+ sh 'git pull origin master'
23
+ sh "git checkout '#{ref}'"
24
+ changed << parent
25
+ else
26
+ say "Working directory isn't clean, skipping"
27
+ errors << path
28
+ end
29
+ end
30
+ end
31
+ if changed.any?
32
+ say "---\nPlease check and commit the following parent repositories:\n#{format_list changed}"
33
+ end
34
+ if errors.any?
35
+ say "---\nCould not update the following locations:\n#{format_list errors}"
36
+ end
37
+ end
38
+
39
+ #######
40
+ private
41
+ #######
42
+
43
+ def format_list(list)
44
+ list.map { |item| " #{item}" }.join("\n")
45
+ end
46
+
47
+ def clean?
48
+ `git status` =~ /working directory clean/
49
+ end
50
+
51
+ def valid?(path)
52
+ return false unless Brigit.submodule?(path)
53
+ config_file = File.join(path, '.git/config')
54
+ url = config_parser.parse(File.readlines(config_file))['remote "origin"']['url'] rescue nil
55
+ return false unless url
56
+ normalize(submodule_url) == normalize(url)
57
+ end
58
+
59
+ def config_parser
60
+ @config_parser ||= ConfigParser.new
61
+ end
62
+
63
+ def check_url!
64
+ fail "Submodule URL required" unless submodule_url
65
+ end
66
+
67
+ def normalize(url)
68
+ url =~ /\.git$/ ? url : "#{url}.git"
69
+ end
70
+
71
+ def submodule_url
72
+ @submodule_url ||= args.shift
73
+ end
74
+
75
+ def submodules
76
+ @submodules ||= begin
77
+ list = []
78
+ Brigit.at_repos(true) do |path|
79
+ list << [path, Brigit.parent_of(path)] if valid?(path)
80
+ end
81
+ list
82
+ end
83
+ end
84
+
85
+ def default_ref
86
+ 'master'
87
+ end
88
+
89
+ end
90
+
91
+ end