right_develop 1.2.2 → 2.0.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.
@@ -1,74 +0,0 @@
1
- module RightDevelop::Git
2
- # A branch in a Git repository. Has some proxy methods that make it act a bit like
3
- # a string, whose value is the name of the branch. This allows branches to be sorted,
4
- # matched against Regexp, and certain other string-y operations.
5
- class Branch
6
- BRANCH_NAME = '[#A-Za-z0-9._\/-]+'
7
- BRANCH_INFO = /(\* | )?(#{BRANCH_NAME})( -> )?(#{BRANCH_NAME})?/
8
- BRANCH_FULLNAME = /(remotes\/)?(#{BRANCH_NAME})/
9
-
10
- def initialize(repo, line)
11
- match = BRANCH_INFO.match(line)
12
- if match && (fullname = match[2])
13
- match = BRANCH_FULLNAME.match(fullname)
14
- if match
15
- @fullname = match[2]
16
- @remote = !!match[1]
17
- @repo = repo
18
- else
19
- raise FormatError, "Unrecognized branch name '#{line}'"
20
- end
21
- else
22
- raise FormatError, "Unrecognized branch info '#{line}'"
23
- end
24
- end
25
-
26
- def to_s
27
- @fullname
28
- end
29
- alias inspect to_s
30
-
31
- def =~(other)
32
- @fullname =~ other
33
- end
34
-
35
- def ==(other)
36
- self.to_s == other.to_s
37
- end
38
-
39
- def <=>(other)
40
- self.to_s <=> other.to_s
41
- end
42
-
43
- def remote?
44
- @remote
45
- end
46
-
47
- def name
48
- if remote?
49
- #remove the initial remote-name in the branch (origin/master --> master)
50
- bits = @fullname.split('/')
51
- bits.shift
52
- bits.join('/')
53
- else
54
- @fullname
55
- end
56
- end
57
-
58
- def display(width=40)
59
- if @fullname.length >= width
60
- (@fullname[0..(width-5)] + "...").ljust(width)
61
- else
62
- @fullname.ljust(width)
63
- end
64
- end
65
-
66
- def delete
67
- if self.remote?
68
- @repo.shell("git push origin :#{self.name}")
69
- else
70
- @repo.shell("git branch -D #{@fullname}")
71
- end
72
- end
73
- end
74
- end
@@ -1,72 +0,0 @@
1
- module RightDevelop::Git
2
- # A collection of Git branches. Acts a bit like an Array, allowing it to be mapped,
3
- # sorted and compared as such.
4
- class BranchCollection
5
- def initialize(repo, *args)
6
- @repo = repo
7
- @branches = args
8
- end
9
-
10
- def to_s
11
- @branches.inspect
12
- end
13
- alias inspect to_s
14
-
15
- def local
16
- local = BranchCollection.new(@repo)
17
- @branches.each do |branch|
18
- local << branch unless branch.remote?
19
- end
20
- local
21
- end
22
-
23
- def remote
24
- remote = BranchCollection.new(@repo)
25
- @branches.each do |branch|
26
- remote << branch if branch.remote?
27
- end
28
- remote
29
- end
30
-
31
- def merged(target)
32
- merged = BranchCollection.new(@repo)
33
-
34
- all_merged = shell("git branch -r --merged #{target}").map do |line|
35
- Branch.new(@repo, line)
36
- end
37
-
38
- @branches.each do |candidate|
39
- # For some reason Set#include? does not play nice with our overridden comparison operators
40
- # for branches, so we need to do this the hard way :(
41
- merged << candidate if all_merged.detect { |b| candidate == b }
42
- end
43
-
44
- merged
45
- end
46
-
47
- # Accessor that acts like either a Hash or Array accessor
48
- def [](argument)
49
- case argument
50
- when String
51
- target = Branch.new(@repo, argument)
52
- @branches.detect { |b| b == target }
53
- else
54
- @branches.__send__(:[], argument)
55
- end
56
- end
57
-
58
- def method_missing(meth, *args, &block)
59
- result = @branches.__send__(meth, *args, &block)
60
-
61
- if result.is_a?(Array)
62
- BranchCollection.new(@repo, *result)
63
- else
64
- result
65
- end
66
- end
67
-
68
- def shell(cmd, *args)
69
- @repo.shell(cmd, *args)
70
- end
71
- end
72
- end
@@ -1,30 +0,0 @@
1
- module RightDevelop::Git
2
- # A commit within a Git repository.
3
- class Commit
4
- COMMIT_INFO = /([0-9A-Fa-f]+) ([0-9]+) (.*)/
5
-
6
- def initialize(repo, line)
7
- @repo = repo
8
- match = COMMIT_INFO.match(line)
9
- raise FormatError, "Unrecognized commit summary '#{line}'" unless match && match.length >= 3
10
- @info = [ match[1], match[2], match[3] ]
11
- end
12
-
13
- def to_s
14
- @info.join(' ')
15
- end
16
-
17
- def hash
18
- # This overrides String#hash on purpose
19
- @info[0]
20
- end
21
-
22
- def timestamp
23
- Time.at(@info[1].to_i)
24
- end
25
-
26
- def author
27
- @info[2]
28
- end
29
- end
30
- end
@@ -1,57 +0,0 @@
1
- module RightDevelop::Git
2
- # An entire Git repository. Mostly acts as a factory for Branch,
3
- # BranchCollection and Commit objects.
4
- class Repository
5
- DEFAULT_LOG_OPTIONS = {
6
- :tail=>1_000
7
- }
8
-
9
- def initialize(dir)
10
- @dir = dir
11
- end
12
-
13
- def fetch
14
- shell('git fetch -q')
15
- end
16
-
17
- def branches()
18
- lines = shell('git branch -a')
19
- branches = BranchCollection.new(self)
20
- lines.each do |line|
21
- branch = Branch.new(self, line)
22
- branches << branch if branch
23
- end
24
- branches
25
- end
26
-
27
- def log(branch_spec='master', options={})
28
- options = DEFAULT_LOG_OPTIONS.merge(options)
29
-
30
- args = [
31
- "-n#{options[:tail]}",
32
- "--format='%h %at %aE'"
33
- ]
34
- if options[:no_merges]
35
- args << "--no-merges"
36
- end
37
-
38
- lines = shell("git log #{args.join(' ')} #{branch_spec}")
39
- lines.map do |line|
40
- Commit.new(self, line)
41
- end.compact
42
- end
43
-
44
- def shell(cmd, *args)
45
- Dir.chdir(@dir) do
46
-
47
- full_cmd="#{cmd} #{args.join ' '}"
48
- output = `#{full_cmd}`
49
- if $?.success?
50
- return output.split("\n").map { |l| l.strip }
51
- else
52
- raise CommandError, "#{full_cmd} --> #{output}"
53
- end
54
- end
55
- end
56
- end
57
- end