git_fame 1.4.2 → 1.5.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +8 -1
- data/bin/git-fame +5 -3
- data/lib/git_fame/base.rb +61 -32
- data/lib/git_fame/version.rb +1 -1
- data/spec/git_fame_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8bb9724458ff2755921443d6d9ac63cbeec1d1f
|
4
|
+
data.tar.gz: a39b694ad844e5020bc062b39dcbd744d3ac57c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0499b7494115af787d7cd64a07e2ae8276e18a7b2141d7ce33d5bd14b2b426c56bf85488fae4ed00195e50273d9fb3df479e6b6e3aa2a6f7dc17b715c600788
|
7
|
+
data.tar.gz: 0b740f88d34139fc9f1be37fdf30313889a0148ebdd3710d0c53c265b8782017666cb5bf246ee21e86e3ce6322b6c86f58836964c4e3474fea43538cc7db911b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -54,6 +54,7 @@ Run `git fame` to generate output as above.
|
|
54
54
|
- `git fame --whitespace` Ignore whitespace changes when blaming files. Default is `false`.
|
55
55
|
- `git fame --repository=/path/to/repo` Git repository to be used. Default is the current folder.
|
56
56
|
- `git fame --branch=master` Branch to run on. Default is `master`.
|
57
|
+
- `git fame --format=output` Output format. Default is `pretty`. Additional: csv.
|
57
58
|
|
58
59
|
### Class
|
59
60
|
|
@@ -68,6 +69,7 @@ Want to work with the data before printing it?
|
|
68
69
|
- **bytype** (Boolean) Should a breakout of line counts by file type be output? Default is 'false'
|
69
70
|
- **exclude** (String) Comma separated paths to exclude from the counts. Default is none.
|
70
71
|
- **branch** (String) Branch to run on. Default is `master`.
|
72
|
+
- **format** (String) Output format. Default is `pretty`.
|
71
73
|
|
72
74
|
``` ruby
|
73
75
|
repository = GitFame::Base.new({
|
@@ -77,7 +79,8 @@ repository = GitFame::Base.new({
|
|
77
79
|
whitespace: false
|
78
80
|
bytype: false,
|
79
81
|
exclude: "vendor, public/assets",
|
80
|
-
branch: "master"
|
82
|
+
branch: "master",
|
83
|
+
format: "pretty"
|
81
84
|
})
|
82
85
|
```
|
83
86
|
|
@@ -85,6 +88,10 @@ repository = GitFame::Base.new({
|
|
85
88
|
|
86
89
|
`repository.pretty_puts`
|
87
90
|
|
91
|
+
#### Print csv table to console
|
92
|
+
|
93
|
+
`repository.csv_puts
|
94
|
+
|
88
95
|
### Statistics
|
89
96
|
|
90
97
|
#### GitFame
|
data/bin/git-fame
CHANGED
@@ -5,7 +5,7 @@ require "trollop"
|
|
5
5
|
|
6
6
|
sort = ["name", "commits", "loc", "files"]
|
7
7
|
opts = Trollop::options do
|
8
|
-
version "git-fame #{GitFame::VERSION} (c)
|
8
|
+
version "git-fame #{GitFame::VERSION} (c) 2015 Linus Oleander"
|
9
9
|
opt :repository, "What git repository should be used?", default: "."
|
10
10
|
opt :sort, "What should the printed table be sorted by? #{sort.join(", ")}", default: "loc", type: String
|
11
11
|
opt :progressbar, "Show progressbar during calculation", default: 1, type: Integer
|
@@ -14,11 +14,12 @@ opts = Trollop::options do
|
|
14
14
|
opt :include, "Paths to include in git ls-files", default: "", type: String
|
15
15
|
opt :exclude, "Paths to exclude (comma separated)", default: "", type: String
|
16
16
|
opt :branch, "Branch to run on", default: "master", type: String
|
17
|
+
opt :format, "Format (pretty/csv)", default: "pretty", type: String
|
17
18
|
end
|
18
19
|
|
19
20
|
Trollop::die :repository, "is not a git repository" unless GitFame::Base.git_repository?(opts[:repository])
|
20
21
|
Trollop::die :sort, "must be one of the following; #{sort.join(", ")}" unless sort.include?(opts[:sort])
|
21
|
-
GitFame::Base.new({
|
22
|
+
fame = GitFame::Base.new({
|
22
23
|
repository: opts[:repository],
|
23
24
|
progressbar: opts[:progressbar] == 1,
|
24
25
|
sort: opts[:sort],
|
@@ -27,4 +28,5 @@ GitFame::Base.new({
|
|
27
28
|
include: opts[:include],
|
28
29
|
exclude: opts[:exclude],
|
29
30
|
branch: opts[:branch]
|
30
|
-
})
|
31
|
+
})
|
32
|
+
opts[:format] == "csv" ? fame.csv_puts : fame.pretty_puts
|
data/lib/git_fame/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "string-scrub"
|
2
|
+
require "csv"
|
2
3
|
require_relative "./errors"
|
3
4
|
|
4
5
|
module GitFame
|
@@ -29,22 +30,62 @@ module GitFame
|
|
29
30
|
@branch = (@branch.nil? or @branch.empty?) ? "master" : @branch
|
30
31
|
end
|
31
32
|
|
33
|
+
#
|
34
|
+
# @return Boolean Is the given @dir a git repository?
|
35
|
+
# @dir Path (relative or absolute) to git repository
|
36
|
+
#
|
37
|
+
def self.git_repository?(dir)
|
38
|
+
return false unless File.directory?(dir)
|
39
|
+
Dir.chdir(dir) do
|
40
|
+
system "git rev-parse --git-dir > /dev/null 2>&1"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
32
44
|
#
|
33
45
|
# Generates pretty output
|
34
46
|
#
|
35
47
|
def pretty_puts
|
36
48
|
extend Hirb::Console
|
37
|
-
Hirb.enable({pager: false})
|
49
|
+
Hirb.enable({ pager: false })
|
38
50
|
puts "\nTotal number of files: #{number_with_delimiter(files)}"
|
39
51
|
puts "Total number of lines: #{number_with_delimiter(loc)}"
|
40
52
|
puts "Total number of commits: #{number_with_delimiter(commits)}\n"
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
54
|
+
table(authors, fields: fields)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Prints CSV
|
59
|
+
#
|
60
|
+
def csv_puts
|
61
|
+
puts to_csv
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Generate csv output
|
66
|
+
#
|
67
|
+
def to_csv
|
68
|
+
CSV.generate do |csv|
|
69
|
+
csv << fields
|
70
|
+
authors.each do |author|
|
71
|
+
csv << fields.map do |f|
|
72
|
+
author.send(f)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Calculate columns to show
|
80
|
+
#
|
81
|
+
def fields
|
82
|
+
@_fields ||= begin
|
83
|
+
fields = [:name, :loc, :commits, :files, :distribution]
|
84
|
+
if @bytype
|
85
|
+
fields += populate.instance_variable_get("@file_extensions")
|
86
|
+
end
|
87
|
+
fields.uniq
|
46
88
|
end
|
47
|
-
table(authors, fields: fields.flatten)
|
48
89
|
end
|
49
90
|
|
50
91
|
#
|
@@ -80,33 +121,22 @@ module GitFame
|
|
80
121
|
# @return Array<Author> A list of authors
|
81
122
|
#
|
82
123
|
def authors
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
124
|
+
@_authors ||= begin
|
125
|
+
authors = populate.instance_variable_get("@authors").values
|
126
|
+
if @sort
|
127
|
+
authors.sort_by do |author|
|
128
|
+
if @sort == "name"
|
129
|
+
author.send(@sort)
|
130
|
+
else
|
131
|
+
-1 * author.send("raw_#{@sort}")
|
132
|
+
end
|
90
133
|
end
|
134
|
+
else
|
135
|
+
authors
|
91
136
|
end
|
92
|
-
else
|
93
|
-
authors
|
94
137
|
end
|
95
138
|
end
|
96
139
|
|
97
|
-
#
|
98
|
-
# @return Boolean Is the given @dir a git repository?
|
99
|
-
# @dir Path (relative or absolute) to git repository
|
100
|
-
#
|
101
|
-
def self.git_repository?(dir)
|
102
|
-
return false unless File.directory?(dir)
|
103
|
-
Dir.chdir(dir) do
|
104
|
-
system "git rev-parse --git-dir > /dev/null 2>&1"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
140
|
#
|
111
141
|
# @return Boolean Does the branch exist?
|
112
142
|
#
|
@@ -116,13 +146,13 @@ module GitFame
|
|
116
146
|
end
|
117
147
|
end
|
118
148
|
|
149
|
+
private
|
150
|
+
|
119
151
|
#
|
120
152
|
# @command String Command to be executed inside the @repository path
|
121
153
|
#
|
122
154
|
def execute(command)
|
123
|
-
Dir.chdir(@repository)
|
124
|
-
return `#{command}`.scrub
|
125
|
-
end
|
155
|
+
Dir.chdir(@repository) { `#{command}`.scrub }
|
126
156
|
end
|
127
157
|
|
128
158
|
#
|
@@ -183,7 +213,6 @@ module GitFame
|
|
183
213
|
# only count extensions that aren't binary
|
184
214
|
@file_extensions << file_extension
|
185
215
|
|
186
|
-
|
187
216
|
output = execute(
|
188
217
|
"git blame #{blame_opts} --line-porcelain #{@branch} -- '#{file}'"
|
189
218
|
)
|
data/lib/git_fame/version.rb
CHANGED
data/spec/git_fame_spec.rb
CHANGED
@@ -118,6 +118,21 @@ describe GitFame::Base do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
describe "#csv_print" do
|
122
|
+
it "should print" do
|
123
|
+
lambda {
|
124
|
+
subject.csv_puts
|
125
|
+
}.should_not raise_error
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should be equal to" do
|
129
|
+
subject.to_csv.should eq("name,loc,commits,files,distribution\n" \
|
130
|
+
"Magnus Holm,586,41,4,54.2 / 58.6 / 25.0\n" \
|
131
|
+
"7rans,360,6,10,33.3 / 8.6 / 62.5\n" \
|
132
|
+
"Linus Oleander,136,23,7,12.6 / 32.9 / 43.8\n")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
121
136
|
describe ".git_repository?" do
|
122
137
|
it "should know if a folder is a git repository [absolute path]" do
|
123
138
|
GitFame::Base.git_repository?(@repository).should eq(true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_fame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linus Oleander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: progressbar
|