Skip to content

Commit

Permalink
Merge pull request #78 from github/git-submodule-files
Browse files Browse the repository at this point in the history
Use `git ls-files` instead of `git ls-tree` to find files in the git repo
  • Loading branch information
jonabc authored Sep 7, 2018
2 parents 551d9b0 + 036a0df commit 47fd851
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 2 additions & 8 deletions lib/licensed/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ def repository_root
# descriptor - file or directory to retrieve latest SHA for
def version(descriptor)
return unless available? && descriptor

dir = File.directory?(descriptor) ? descriptor : File.dirname(descriptor)
file = File.directory?(descriptor) ? "." : File.basename(descriptor)

Dir.chdir dir do
Licensed::Shell.execute("git", "rev-list", "-1", "HEAD", "--", file, allow_failure: true)
end
Licensed::Shell.execute("git", "rev-list", "-1", "HEAD", "--", descriptor, allow_failure: true)
end

# Returns the commit date for the provided SHA as a timestamp
Expand All @@ -37,7 +31,7 @@ def commit_date(sha)

def files
return unless available?
output = Licensed::Shell.execute("git", "ls-tree", "--full-tree", "-r", "--name-only", "HEAD")
output = Licensed::Shell.execute("git", "ls-files", "--full-name", "--recurse-submodules")
output.lines.map(&:strip)
end
end
Expand Down
14 changes: 13 additions & 1 deletion lib/licensed/source/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ def dependencies
"summary" => package["Doc"],
"homepage" => homepage(import_path),
"search_root" => search_root(package_dir),
"version" => Licensed::Git.version(package_dir)
"version" => package_version(package_dir)
})
end.compact
end
end

# Returns the most recent git SHA for a package, or nil if SHA is
# not available
#
# package_directory - package location
def package_version(package_directory)
return unless package_directory

Dir.chdir package_directory do
Licensed::Git.version(".")
end
end

# Returns the homepage for a package import_path. Assumes that the
# import path itself is a url domain and path
def homepage(import_path)
Expand Down
2 changes: 1 addition & 1 deletion test/license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
end

it "returns true if the normalized content is the same" do
license = Licensed::License.new({}, "test content")
license = Licensed::License.new({}, "- test content")
other = Licensed::License.new({}, "* test content")

assert license.license_text_match?(other)
Expand Down

0 comments on commit 47fd851

Please sign in to comment.