forked from lilyball/six
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows you to specify a local source for fast lookups. Currently, it doesn't support an url (as it's local), but it would be nice to be able to point to a gitweb site. To do this, we probably have to extend the repo list format, though.
- Loading branch information
Showing
6 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Git::Source::Local | ||
|
||
Git::Source::Source.add_handler(/file:\/\//, self) | ||
def self.public?; false; end | ||
|
||
class RepositoryNotFoundError < RuntimeError; end | ||
def initialize(url) | ||
url =~ /file:\/\/(.*)/ | ||
@location = $1 | ||
command("git rev-parse") | ||
ret = $? | ||
raise RepositoryNotFoundError.new unless ret == 0 | ||
end | ||
|
||
def name | ||
return File.basename(@location).gsub(/\.git$/, "") | ||
end | ||
|
||
def matches?(match) | ||
return name =~ /#{match}/ | ||
end | ||
|
||
def command(cmd) | ||
`(cd #{@location} && #{cmd}) 2>/dev/null`.strip | ||
end | ||
|
||
def lookup(ref, file) | ||
if file | ||
file_add = ":#{file}" | ||
else | ||
file_add = "" | ||
end | ||
|
||
type = command("git cat-file -t #{ref}#{file_add} 2> /dev/null") | ||
return nil unless $? == 0 | ||
subject = nil | ||
if type == "commit" | ||
details = command("git cat-file commit #{ref}") | ||
if details =~ /\n\n(.+)$/ | ||
subject = $1 | ||
end | ||
end | ||
# Point to commitdiff and not commitpage when referring a commit | ||
return { | ||
:file => file, | ||
:ref => ref, | ||
:type => type, | ||
:url => nil, | ||
:subject => subject, | ||
:reponame => name | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
$: << File.join(File.dirname(__FILE__), "..", "..", "..", "lib") | ||
require 'git' | ||
require 'fileutils' | ||
require 'test/unit' | ||
require 'ostruct' | ||
|
||
GIT_DIR = "/tmp/tmptestgitdir" | ||
FileUtils.remove_dir(GIT_DIR) if File.exist?(GIT_DIR) | ||
|
||
`mkdir #{GIT_DIR}; cd #{GIT_DIR}; git init; touch a; mkdir b; touch b/c; git add a; git commit -m "First commit"; git add b/c; git commit -m "a commit";` | ||
|
||
class GitwebTest < Test::Unit::TestCase | ||
|
||
def setup | ||
@source = Git::Source::Local.new("file://" + GIT_DIR) | ||
end | ||
|
||
def test_false_repo | ||
assert_raise(Git::Source::Local::RepositoryNotFoundError) do | ||
Git::Source::Local.new("file:///tmp/dosutaosu") | ||
end | ||
end | ||
|
||
def test_matches | ||
assert(@source.matches?(/tmptest/)) | ||
assert(@source.matches?(/tmptestgitdir/)) | ||
assert(!@source.matches?(/temp-test/)) | ||
end | ||
|
||
def test_name | ||
assert_equal("tmptestgitdir", @source.name) | ||
end | ||
|
||
def test_lookup_HEAD | ||
l = @source.lookup("HEAD", nil) | ||
assert(l) | ||
assert_equal(nil, l[:url]) | ||
assert_equal("commit", l[:type]) | ||
assert_equal("a commit", l[:subject]) | ||
end | ||
|
||
def test_lookup_false_branch | ||
l = @source.lookup("Nonexisting branch", nil) | ||
assert_nil(l) | ||
end | ||
|
||
def test_lookup_tree | ||
l = @source.lookup("HEAD", "b") | ||
assert(l) | ||
assert_equal("tree", l[:type]) | ||
assert_equal("b", l[:file]) | ||
end | ||
|
||
def test_lookup_blob | ||
l = @source.lookup("HEAD", "a") | ||
assert(l) | ||
assert_equal("blob", l[:type]) | ||
assert_equal("a", l[:file]) | ||
end | ||
|
||
def test_create | ||
a = Git::Source::Source.create("file://" + GIT_DIR) | ||
assert(a.is_a?(Git::Source::Local)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ carnique: | |
- "repo:git.git" | ||
- "repo:egit.git" | ||
- "http://git.frim.nl/?p=gitbot.git" | ||
- "file:///tmp/tmptestgitdir" |