Skip to content

Commit

Permalink
Merge f9784c8 into a0ea821
Browse files Browse the repository at this point in the history
  • Loading branch information
magni- committed Mar 3, 2016
2 parents a0ea821 + f9784c8 commit 3d886e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions bin/git-fame
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ opts = Trollop::options do
opt :bytype, "Group line counts by file extension (i.e. .rb, .erb, .yml)", default: false
opt :include, "Paths to include in git ls-files", default: "", type: String
opt :exclude, "Paths to exclude (comma separated)", default: "", type: String
opt :extension, "Comma-separated list of extensions to consider, leave blank for all", default: "", type: String
opt :branch, "Branch to run on", default: "master", type: String
opt :format, "Format (pretty/csv)", default: "pretty", type: String
end
Expand All @@ -27,6 +28,7 @@ fame = GitFame::Base.new({
bytype: opts[:bytype],
include: opts[:include],
exclude: opts[:exclude],
extensions: opts[:extension],
branch: opts[:branch]
})
opts[:format] == "csv" ? fame.csv_puts : fame.pretty_puts
16 changes: 13 additions & 3 deletions lib/git_fame/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(args)
@progressbar = false
@whitespace = false
@bytype = false
@extensions = ""
@exclude = ""
@include = ""
@authors = {}
Expand All @@ -27,6 +28,7 @@ def initialize(args)
instance_variable_set "@" + name.to_s, args[name]
end
@exclude = convert_exclude_paths_to_array
@extensions = convert_extensions_to_array
@branch = (@branch.nil? or @branch.empty?) ? "master" : @branch
end

Expand Down Expand Up @@ -185,8 +187,9 @@ def populate
raise BranchNotFound.new("Does '#{@branch}' exist?")
end

@files = execute("git ls-tree -r #{@branch} --name-only #{@include}").
split("\n")
command = "git ls-tree -r #{@branch} --name-only #{@include}"
command += " | grep \"\\.\\(#{@extensions.join("\\|")}\\)$\"" unless @extensions.empty?
@files = execute(command).split("\n")
@file_extensions = []
remove_excluded_files
progressbar = SilentProgressbar.new(
Expand Down Expand Up @@ -260,13 +263,20 @@ def convert_exclude_paths_to_array
@exclude.split(",").map{|path| path.strip.sub(/\A\//, "") }
end

#
# Converts @extensions argument to an array
#
def convert_extensions_to_array
@extensions.split(",")
end

#
# Removes files matching paths in @exclude from @files instance variable
#
def remove_excluded_files
return if @exclude.empty?
@files = @files.map do |path|
next if path =~ /\A(#{@exclude.join("|")})/
next if path =~ /\A(#{@exclude.join("|")})/
path
end.compact
end
Expand Down
33 changes: 19 additions & 14 deletions spec/git_fame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
end
end
describe "format" do
let(:author) do
let(:author) do
GitFame::Author.new({
raw_commits: 12345,
raw_files: 6789,
raw_commits: 12345,
raw_files: 6789,
raw_loc: 1234
})
end
Expand Down Expand Up @@ -61,7 +61,7 @@
describe "sort" do
it "should be able to sort #authors by name" do
authors = GitFame::Base.new({
repository: @repository,
repository: @repository,
sort: "name"
}).authors
authors.map(&:name).
Expand All @@ -70,7 +70,7 @@

it "should be able to sort #authors by commits" do
authors = GitFame::Base.new({
repository: @repository,
repository: @repository,
sort: "commits"
}).authors
authors.map(&:name).
Expand All @@ -79,7 +79,7 @@

it "should be able to sort #authors by files" do
authors = GitFame::Base.new({
repository: @repository,
repository: @repository,
sort: "files"
}).authors
authors.map(&:name).
Expand All @@ -88,19 +88,24 @@
end

describe "#command_line_arguments" do
let(:subject) do
let(:subject) do
GitFame::Base.new({
repository: @repository,
exclude: "lib",
bytype: true
})
repository: @repository,
exclude: "lib",
bytype: true,
extensions: "rb,rdoc"
})
end

it "should exclude the lib folder" do
subject.file_list.include?("lib/gash.rb").should be_false
end

let(:author) { subject.authors.first }
it "should exclude non rb or rdoc files" do
subject.file_list.include?("HISTORY").should be_false
end

let(:author) { subject.authors.find { |author| author.name == "7rans" } }
it "should break out counts by file type" do
author.file_type_counts["rdoc"].should eq(23)
end
Expand Down Expand Up @@ -156,7 +161,7 @@
describe "branches" do
it "should handle existing branches" do
authors = GitFame::Base.new({
repository: @repository,
repository: @repository,
branch: "0.1.0"
}).authors

Expand All @@ -167,7 +172,7 @@
it "should raise an error if branch doesn't exist" do
expect {
GitFame::Base.new({
repository: @repository,
repository: @repository,
branch: "f67c2bcbfcfa30fccb36f72dca22a817"
}).authors
}.to raise_error(GitFame::BranchNotFound)
Expand Down

0 comments on commit 3d886e0

Please sign in to comment.