brigit 0.8.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 +15 -0
- data/README.rdoc +36 -0
- data/Rakefile +15 -0
- data/bin/brigit +8 -0
- data/brigit.gemspec +55 -0
- data/lib/brigit.rb +24 -0
- data/lib/brigit/cli.rb +61 -0
- data/lib/brigit/commands/command.rb +34 -0
- data/lib/brigit/commands/map_command.rb +55 -0
- data/lib/brigit/commands/update_command.rb +20 -0
- data/lib/brigit/config_parser.rb +90 -0
- data/lib/brigit/version.rb +86 -0
- data/lib/ext/option_parser.rb +13 -0
- data/test/config_parser_test.rb +42 -0
- data/test/fixtures/example.conf +23 -0
- data/test/test_helper.rb +6 -0
- metadata +83 -0
data/Manifest
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
bin/brigit
|
|
2
|
+
lib/brigit/cli.rb
|
|
3
|
+
lib/brigit/commands/command.rb
|
|
4
|
+
lib/brigit/commands/map_command.rb
|
|
5
|
+
lib/brigit/commands/update_command.rb
|
|
6
|
+
lib/brigit/config_parser.rb
|
|
7
|
+
lib/brigit/version.rb
|
|
8
|
+
lib/brigit.rb
|
|
9
|
+
lib/ext/option_parser.rb
|
|
10
|
+
Rakefile
|
|
11
|
+
README.rdoc
|
|
12
|
+
test/config_parser_test.rb
|
|
13
|
+
test/fixtures/example.conf
|
|
14
|
+
test/test_helper.rb
|
|
15
|
+
Manifest
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
= Brigit
|
|
2
|
+
|
|
3
|
+
A random collection of utilities for developers working with Git repositories.
|
|
4
|
+
|
|
5
|
+
== Contributing
|
|
6
|
+
|
|
7
|
+
Feel free to fork, send patches, etc. Development is done at http://github.com/fiveruns/brigit
|
|
8
|
+
|
|
9
|
+
== Authors
|
|
10
|
+
|
|
11
|
+
The FiveRuns development team, http://www.fiveruns.org
|
|
12
|
+
|
|
13
|
+
== License
|
|
14
|
+
|
|
15
|
+
# (The FiveRuns License)
|
|
16
|
+
#
|
|
17
|
+
# Copyright (c) 2006-2008 FiveRuns Corporation
|
|
18
|
+
#
|
|
19
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
20
|
+
# a copy of this software and associated documentation files (the
|
|
21
|
+
# 'Software'), to deal in the Software without restriction, including
|
|
22
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
23
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
24
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
25
|
+
# the following conditions:
|
|
26
|
+
#
|
|
27
|
+
# The above copyright notice and this permission notice shall be
|
|
28
|
+
# included in all copies or substantial portions of the Software.
|
|
29
|
+
#
|
|
30
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
31
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
32
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
33
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
34
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
35
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
36
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'echoe'
|
|
3
|
+
|
|
4
|
+
require File.dirname(__FILE__) << "/lib/brigit/version"
|
|
5
|
+
|
|
6
|
+
Echoe.new 'brigit' do |p|
|
|
7
|
+
p.version = Brigit::Version::STRING
|
|
8
|
+
p.author = "FiveRuns Development Team"
|
|
9
|
+
p.email = 'dev@fiveruns.com'
|
|
10
|
+
p.project = 'fiveruns'
|
|
11
|
+
p.summary = "Git utilities"
|
|
12
|
+
p.url = "http://github.com/fiveruns/brigit"
|
|
13
|
+
p.include_rakefile = true
|
|
14
|
+
end
|
|
15
|
+
|
data/bin/brigit
ADDED
data/brigit.gemspec
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
# Gem::Specification for Brigit-0.8.1
|
|
3
|
+
# Originally generated by Echoe
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = %q{brigit}
|
|
7
|
+
s.version = "0.8.1"
|
|
8
|
+
|
|
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/map_command.rb", "lib/brigit/commands/update_command.rb", "lib/brigit/config_parser.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/map_command.rb", "lib/brigit/commands/update_command.rb", "lib/brigit/config_parser.rb", "lib/brigit/version.rb", "lib/brigit.rb", "lib/ext/option_parser.rb", "Rakefile", "README.rdoc", "test/config_parser_test.rb", "test/fixtures/example.conf", "test/test_helper.rb", "Manifest", "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"]
|
|
26
|
+
|
|
27
|
+
if s.respond_to? :specification_version then
|
|
28
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
29
|
+
s.specification_version = 2
|
|
30
|
+
|
|
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
|
+
#
|
data/lib/brigit.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'find'
|
|
2
|
+
|
|
3
|
+
module Brigit
|
|
4
|
+
|
|
5
|
+
def self.at_dot_gitmodules
|
|
6
|
+
Find.find(Dir.pwd) do |path|
|
|
7
|
+
if File.basename(path) == '.git' && File.directory?(path)
|
|
8
|
+
Find.prune
|
|
9
|
+
elsif File.file?(File.join(path, '.gitmodules'))
|
|
10
|
+
Dir.chdir path do
|
|
11
|
+
yield path
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
$:.unshift File.dirname(__FILE__)
|
|
20
|
+
|
|
21
|
+
# Require all files
|
|
22
|
+
Dir[File.dirname(__FILE__) << "/**/*.rb"].each do |file|
|
|
23
|
+
require file
|
|
24
|
+
end
|
data/lib/brigit/cli.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
|
|
3
|
+
module Brigit
|
|
4
|
+
|
|
5
|
+
class CLI
|
|
6
|
+
|
|
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)
|
|
11
|
+
else
|
|
12
|
+
abort "No command given.\n#{parser}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.usage
|
|
17
|
+
parser.to_s
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#######
|
|
21
|
+
private
|
|
22
|
+
#######
|
|
23
|
+
|
|
24
|
+
def self.options
|
|
25
|
+
@options ||= OpenStruct.new
|
|
26
|
+
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
|
+
|
|
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
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'brigit/listable'
|
|
2
|
+
require 'brigit/fallible'
|
|
3
|
+
|
|
4
|
+
module Brigit
|
|
5
|
+
|
|
6
|
+
class Command
|
|
7
|
+
include Listable
|
|
8
|
+
include Fallible
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :help
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_reader :options, :args
|
|
15
|
+
def initialize(options, *args)
|
|
16
|
+
@options = options
|
|
17
|
+
@args = args
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def execute!
|
|
21
|
+
raise ArgumentError, "Must be in Git repository" unless repo?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#######
|
|
25
|
+
private
|
|
26
|
+
#######
|
|
27
|
+
|
|
28
|
+
def repo?
|
|
29
|
+
File.directory?(File.join(Dir.pwd, '.git'))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'brigit/commands/command'
|
|
2
|
+
require 'find'
|
|
3
|
+
|
|
4
|
+
module Brigit
|
|
5
|
+
|
|
6
|
+
class MapCommand < Command
|
|
7
|
+
|
|
8
|
+
self.help = "Graphs of submodules in this repository"
|
|
9
|
+
|
|
10
|
+
def execute!
|
|
11
|
+
super
|
|
12
|
+
text = %|digraph G {\n|
|
|
13
|
+
# TODO: Allow customization
|
|
14
|
+
text << %|ranksep=.75; size = "12,12";\n|
|
|
15
|
+
base = Dir.pwd
|
|
16
|
+
Brigit.at_dot_gitmodules do |path|
|
|
17
|
+
origin = origin_at(path)
|
|
18
|
+
text << %| "#{origin}" [shape="box",style=filled,fillcolor=lightgrey];\n|
|
|
19
|
+
submodules_at(path).each do |submodule|
|
|
20
|
+
text << %| "#{origin}" -> "#{submodule['url']}" [fontsize=16,label="#{submodule['path']}"];\n|
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
text << %|}\n|
|
|
24
|
+
if options.open
|
|
25
|
+
IO.popen("dot -Tpng | open -f -a /Applications/Preview.app", 'w') do |file|
|
|
26
|
+
file.write text
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
puts text
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#######
|
|
34
|
+
private
|
|
35
|
+
#######
|
|
36
|
+
|
|
37
|
+
def origin_at(path)
|
|
38
|
+
filename = File.join(path, '.git/config')
|
|
39
|
+
result = parser.parse(File.readlines(filename))
|
|
40
|
+
result['remote "origin"']['url']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def submodules_at(path)
|
|
44
|
+
filename = File.join(path, '.gitmodules')
|
|
45
|
+
result = parser.parse(File.readlines(filename))
|
|
46
|
+
result.values
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def parser
|
|
50
|
+
@parser ||= ConfigParser.new
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'brigit/commands/command'
|
|
2
|
+
require 'find'
|
|
3
|
+
|
|
4
|
+
module Brigit
|
|
5
|
+
|
|
6
|
+
class UpdateCommand < Command
|
|
7
|
+
|
|
8
|
+
self.help = "Update all submodules in the repo, recursively"
|
|
9
|
+
|
|
10
|
+
def execute!
|
|
11
|
+
super
|
|
12
|
+
Brigit.at_dot_gitmodules do |path|
|
|
13
|
+
system "git submodule init"
|
|
14
|
+
system "git submodule update"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
module Brigit
|
|
2
|
+
|
|
3
|
+
# Reworked from Sam Ruby's Ruby "PythonConfigParser," http://intertwingly.net/code/mars/planet/config.rb
|
|
4
|
+
# which in turn is a port of Python's ConfigParser, http://docs.python.org/lib/module-ConfigParser.html
|
|
5
|
+
class ConfigParser
|
|
6
|
+
|
|
7
|
+
class Section
|
|
8
|
+
|
|
9
|
+
attr_reader :name
|
|
10
|
+
def initialize(name)
|
|
11
|
+
@name = name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def options
|
|
15
|
+
@options ||= {}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def method_missing(*args, &block)
|
|
19
|
+
options.__send__(*args, &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.section_pattern
|
|
25
|
+
@section_pattern ||= /
|
|
26
|
+
\[ # [
|
|
27
|
+
([^\]]+) # very permissive!
|
|
28
|
+
\] # ]
|
|
29
|
+
/x
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.option_pattern
|
|
33
|
+
@option_pattern ||= /
|
|
34
|
+
([^:=\s][^:=]*) # very permissive!
|
|
35
|
+
\s*[:=]\s* # any number of space chars,
|
|
36
|
+
# followed by separator
|
|
37
|
+
# (either : or =), followed
|
|
38
|
+
# by any # space chars
|
|
39
|
+
(.*)$ # everything up to eol
|
|
40
|
+
/x
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# FIXME: This is *way* ugly
|
|
45
|
+
def parse(lines)
|
|
46
|
+
sections = Hash.new { |_, name| Section.new(name) }
|
|
47
|
+
section = nil
|
|
48
|
+
option = nil
|
|
49
|
+
lines.each_with_index do |line, number|
|
|
50
|
+
next if skip? line
|
|
51
|
+
if line =~ self.class.option_pattern
|
|
52
|
+
# option line
|
|
53
|
+
option, value = $1, $2
|
|
54
|
+
option = option.downcase.strip
|
|
55
|
+
value.sub!(/\s;.*/, '')
|
|
56
|
+
value = '' if value == '""'
|
|
57
|
+
section[option] = clean value
|
|
58
|
+
elsif line =~ /^\s/ && section && option
|
|
59
|
+
# continuation line
|
|
60
|
+
value = line.strip
|
|
61
|
+
section[option] = section[option] ? (section[option] << "\n#{clean value}") : clean(value)
|
|
62
|
+
elsif line =~ self.class.section_pattern
|
|
63
|
+
section = sections[$1]
|
|
64
|
+
sections[$1] = section
|
|
65
|
+
option = nil
|
|
66
|
+
elsif !section
|
|
67
|
+
raise SyntaxError, 'Missing section header'
|
|
68
|
+
else
|
|
69
|
+
raise SyntaxError, "Invalid syntax on line #{number}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
sections
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#######
|
|
76
|
+
private
|
|
77
|
+
#######
|
|
78
|
+
|
|
79
|
+
def clean(value)
|
|
80
|
+
value.sub(/\s*#.*/, '')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def skip?(line)
|
|
84
|
+
line.strip.empty? || line =~ /^\s*[#;]/ || line =~ /^rem(\s|$)/i
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# (The MIT License)
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2008 Jamis Buck <jamis@37signals.com>,
|
|
4
|
+
# with modifications by Bruce Williams <bruce@fiveruns.com>
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
# a copy of this software and associated documentation files (the
|
|
8
|
+
# 'Software'), to deal in the Software without restriction, including
|
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
# the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be
|
|
15
|
+
# included in all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
module Brigit
|
|
26
|
+
|
|
27
|
+
# A class for describing the current version of a library. The version
|
|
28
|
+
# consists of three parts: the +major+ number, the +minor+ number, and the
|
|
29
|
+
# +tiny+ (or +patch+) number.
|
|
30
|
+
class Version
|
|
31
|
+
|
|
32
|
+
include Comparable
|
|
33
|
+
|
|
34
|
+
# A convenience method for instantiating a new Version instance with the
|
|
35
|
+
# given +major+, +minor+, and +tiny+ components.
|
|
36
|
+
def self.[](major, minor, tiny)
|
|
37
|
+
new(major, minor, tiny)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.rails
|
|
41
|
+
@rails ||= begin
|
|
42
|
+
# handle ::Rails::VERSION not being set
|
|
43
|
+
Version.new(::Rails::VERSION::MAJOR, ::Rails::VERSION::MINOR, ::Rails::VERSION::TINY) rescue Version.new(0,0,0)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
attr_reader :major, :minor, :tiny
|
|
48
|
+
|
|
49
|
+
# Create a new Version object with the given components.
|
|
50
|
+
def initialize(major, minor, tiny)
|
|
51
|
+
@major, @minor, @tiny = major, minor, tiny
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Compare this version to the given +version+ object.
|
|
55
|
+
def <=>(version)
|
|
56
|
+
to_i <=> version.to_i
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Converts this version object to a string, where each of the three
|
|
60
|
+
# version components are joined by the '.' character. E.g., 2.0.0.
|
|
61
|
+
def to_s
|
|
62
|
+
@to_s ||= [@major, @minor, @tiny].join(".")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Converts this version to a canonical integer that may be compared
|
|
66
|
+
# against other version objects.
|
|
67
|
+
def to_i
|
|
68
|
+
@to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def to_a
|
|
72
|
+
[@major, @minor, @tiny]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
MAJOR = 0
|
|
76
|
+
MINOR = 8
|
|
77
|
+
TINY = 1
|
|
78
|
+
|
|
79
|
+
# The current version as a Version instance
|
|
80
|
+
CURRENT = new(MAJOR, MINOR, TINY)
|
|
81
|
+
# The current version as a String
|
|
82
|
+
STRING = CURRENT.to_s
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
# Fix OptionParser#separator's handling of strings with newlines
|
|
4
|
+
# From http://rubyforge.org/tracker/?func=detail&atid=1700&aid=9177&group_id=426
|
|
5
|
+
class OptionParser
|
|
6
|
+
|
|
7
|
+
def separator(string)
|
|
8
|
+
string.split(/\n/).each do |line|
|
|
9
|
+
top.append(line.chomp, nil, nil)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require File.dirname(__FILE__) << "/test_helper"
|
|
2
|
+
|
|
3
|
+
class ConfigParserTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
attr_reader :results
|
|
6
|
+
|
|
7
|
+
context "ConfigParser" do
|
|
8
|
+
setup do
|
|
9
|
+
@results = parser.parse(File.read(File.dirname(__FILE__) << "/fixtures/example.conf"))
|
|
10
|
+
end
|
|
11
|
+
should "find correct number of sections" do
|
|
12
|
+
assert_equal %w(section1 section2 section3 section4), results.keys.sort
|
|
13
|
+
end
|
|
14
|
+
should "find options" do
|
|
15
|
+
counts = { 1 => 0, 2 => 2, 3 => 2, 4 => 0}
|
|
16
|
+
counts.each do |i, count|
|
|
17
|
+
assert_equal count, results["section#{i}"].size
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
should "ignore comments" do
|
|
21
|
+
assert_equal %w(
|
|
22
|
+
lib/ham
|
|
23
|
+
spam/eggs
|
|
24
|
+
foo/a
|
|
25
|
+
foo/b
|
|
26
|
+
foo/c
|
|
27
|
+
foo/lib/bar
|
|
28
|
+
foo/lib/baz
|
|
29
|
+
foo/lib/quux
|
|
30
|
+
foo/doc/design), results["section3"]['items'].scan(/(\S+)/).flatten
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#######
|
|
35
|
+
private
|
|
36
|
+
#######
|
|
37
|
+
|
|
38
|
+
def parser
|
|
39
|
+
@parser ||= Brigit::ConfigParser.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[section1]
|
|
2
|
+
|
|
3
|
+
[section2]
|
|
4
|
+
writable = gitosis-admin
|
|
5
|
+
members = a b c
|
|
6
|
+
|
|
7
|
+
[section3]
|
|
8
|
+
items = lib/ham
|
|
9
|
+
|
|
10
|
+
spam/eggs
|
|
11
|
+
|
|
12
|
+
foo/a
|
|
13
|
+
foo/b
|
|
14
|
+
foo/c
|
|
15
|
+
foo/lib/bar # this is a comment
|
|
16
|
+
foo/lib/baz
|
|
17
|
+
foo/lib/quux
|
|
18
|
+
foo/doc/design
|
|
19
|
+
# this is a ful line comment
|
|
20
|
+
|
|
21
|
+
members = a b c d e f g
|
|
22
|
+
|
|
23
|
+
[section4]
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: brigit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.8.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- FiveRuns Development Team
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-07-08 00:00:00 -05:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Git utilities
|
|
17
|
+
email: dev@fiveruns.com
|
|
18
|
+
executables:
|
|
19
|
+
- brigit
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- bin/brigit
|
|
24
|
+
- lib/brigit/cli.rb
|
|
25
|
+
- lib/brigit/commands/command.rb
|
|
26
|
+
- lib/brigit/commands/map_command.rb
|
|
27
|
+
- lib/brigit/commands/update_command.rb
|
|
28
|
+
- lib/brigit/config_parser.rb
|
|
29
|
+
- lib/brigit/version.rb
|
|
30
|
+
- lib/brigit.rb
|
|
31
|
+
- lib/ext/option_parser.rb
|
|
32
|
+
- README.rdoc
|
|
33
|
+
files:
|
|
34
|
+
- bin/brigit
|
|
35
|
+
- lib/brigit/cli.rb
|
|
36
|
+
- lib/brigit/commands/command.rb
|
|
37
|
+
- lib/brigit/commands/map_command.rb
|
|
38
|
+
- lib/brigit/commands/update_command.rb
|
|
39
|
+
- lib/brigit/config_parser.rb
|
|
40
|
+
- lib/brigit/version.rb
|
|
41
|
+
- lib/brigit.rb
|
|
42
|
+
- lib/ext/option_parser.rb
|
|
43
|
+
- Rakefile
|
|
44
|
+
- README.rdoc
|
|
45
|
+
- test/config_parser_test.rb
|
|
46
|
+
- test/fixtures/example.conf
|
|
47
|
+
- test/test_helper.rb
|
|
48
|
+
- Manifest
|
|
49
|
+
- brigit.gemspec
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: http://github.com/fiveruns/brigit
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options:
|
|
54
|
+
- --line-numbers
|
|
55
|
+
- --inline-source
|
|
56
|
+
- --title
|
|
57
|
+
- Brigit
|
|
58
|
+
- --main
|
|
59
|
+
- README.rdoc
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: "0"
|
|
67
|
+
version:
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: "0"
|
|
73
|
+
version:
|
|
74
|
+
requirements: []
|
|
75
|
+
|
|
76
|
+
rubyforge_project: fiveruns
|
|
77
|
+
rubygems_version: 1.2.0
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 2
|
|
80
|
+
summary: Git utilities
|
|
81
|
+
test_files:
|
|
82
|
+
- test/config_parser_test.rb
|
|
83
|
+
- test/test_helper.rb
|