Module: Jiragit::Git
- Defined in:
- lib/jiragit/git/branch.rb,
lib/jiragit/git/repository.rb
Defined Under Namespace
Classes: Branch, NoRepositoryError, Repository
Class Method Summary
collapse
Class Method Details
.committer(reference) ⇒ Object
98
99
100
101
102
|
# File 'lib/jiragit/git/repository.rb', line 98
def self.committer(reference)
value = `git log -1 --format=%cN #{reference} 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.current_branch ⇒ Object
19
20
21
22
23
|
# File 'lib/jiragit/git/repository.rb', line 19
def self.current_branch
value = `git symbolic-ref -q HEAD --short 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.current_commit ⇒ Object
25
26
27
28
29
|
# File 'lib/jiragit/git/repository.rb', line 25
def self.current_commit
value = `git log -1 --format=%H 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.github_branch_url(branch = current_branch) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/jiragit/git/repository.rb', line 43
def self.github_branch_url(branch = current_branch)
return unless remote =~ /github.com/
remote
.gsub(/git\@github.com\:/,'https://github.com/')
.gsub(/.git$/,"/tree/#{branch}")
end
|
.github_commit_url(commit) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/jiragit/git/repository.rb', line 50
def self.github_commit_url(commit)
return unless remote =~ /github.com/
remote
.gsub(/git\@github.com\:/,'https://github.com/')
.gsub(/.git$/,"/commit/#{commit}")
end
|
.local_branches ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/jiragit/git/repository.rb', line 75
def self.local_branches
value = `git for-each-ref --sort=-committerdate refs/heads --format="%(objectname) %(refname)" 2>&1`
.split(/\n/)
.map(&:chomp)
.map{ |line| line.split(/ /) }
.map{ |entries|
Branch.new.tap do |branch|
branch.commit = entries.first
branch.name = entries.last
end
}
.sort_by{ |branch| branch.date }
.reverse
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.previous_branch ⇒ Object
31
32
33
34
35
|
# File 'lib/jiragit/git/repository.rb', line 31
def self.previous_branch
value = `git rev-parse --symbolic-full-name --abbrev-ref @{-1} 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.remote ⇒ Object
37
38
39
40
41
|
# File 'lib/jiragit/git/repository.rb', line 37
def self.remote
value = `git config --get remote.origin.url 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.remote_branches ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/jiragit/git/repository.rb', line 57
def self.remote_branches
value = `git fetch 2>&1`
raise NoRepositoryError if value=~/Not a git repository/
`git ls-remote --heads origin 2>&1`
.split(/\n/)
.map(&:chomp)
.map{ |line| line.split(/\t/) }
.map{ |entries|
Branch.new.tap do |branch|
branch.commit = entries.first
branch.name = entries.last
end
}
.sort_by{ |branch| branch.date }
.reverse
end
|
.repository_root ⇒ Object
13
14
15
16
17
|
# File 'lib/jiragit/git/repository.rb', line 13
def self.repository_root
value = `git rev-parse --show-toplevel 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|
.timestamp(reference) ⇒ Object
92
93
94
95
96
|
# File 'lib/jiragit/git/repository.rb', line 92
def self.timestamp(reference)
value = `git log -1 --format=%ci #{reference} 2>&1`.chomp
raise NoRepositoryError if value=~/Not a git repository/
value
end
|