| |   |
| 5 | 5 | LOGS_PER_PAGE = 30 |
| 6 | 6 | |
| 7 | 7 | def index |
| 8 | | @git = Git.bare(@repository.full_repository_path) |
| 8 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 9 | 9 | @commits = @git.log(LOGS_PER_PAGE) |
| 10 | | @tags_per_sha = returning({}) do |hash| |
| 11 | | @git.tags.each do |tag| |
| 12 | | hash[tag.sha] ||= [] |
| 13 | | hash[tag.sha] << tag.name |
| 14 | | end |
| 15 | | end |
| 16 | | # TODO: Patch rails to keep track of what it responds to so we can DRY this up |
| 17 | | @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom) |
| 18 | | respond_to do |format| |
| 19 | | format.html |
| 20 | | format.atom |
| 21 | | end |
| 22 | 10 | end |
| 23 | 11 | |
| 12 | # def index |
| 13 | # @git = Git.bare(@repository.full_repository_path) |
| 14 | # @commits = @git.log(LOGS_PER_PAGE) |
| 15 | # @tags_per_sha = returning({}) do |hash| |
| 16 | # @git.tags.each do |tag| |
| 17 | # hash[tag.sha] ||= [] |
| 18 | # hash[tag.sha] << tag.name |
| 19 | # end |
| 20 | # end |
| 21 | # # TODO: Patch rails to keep track of what it responds to so we can DRY this up |
| 22 | # @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom) |
| 23 | # respond_to do |format| |
| 24 | # format.html |
| 25 | # format.atom |
| 26 | # end |
| 27 | # end |
| 28 | |
| 24 | 29 | def tree |
| 25 | 30 | @git = Git.bare(@repository.full_repository_path) |
| 26 | 31 | @tree = @git.gtree(params[:sha]) |
| toggle raw diff |
--- a/app/controllers/browse_controller.rb
+++ b/app/controllers/browse_controller.rb
@@ -5,22 +5,27 @@ class BrowseController < ApplicationController
LOGS_PER_PAGE = 30
def index
- @git = Git.bare(@repository.full_repository_path)
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
@commits = @git.log(LOGS_PER_PAGE)
- @tags_per_sha = returning({}) do |hash|
- @git.tags.each do |tag|
- hash[tag.sha] ||= []
- hash[tag.sha] << tag.name
- end
- end
- # TODO: Patch rails to keep track of what it responds to so we can DRY this up
- @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
- respond_to do |format|
- format.html
- format.atom
- end
end
+ # def index
+ # @git = Git.bare(@repository.full_repository_path)
+ # @commits = @git.log(LOGS_PER_PAGE)
+ # @tags_per_sha = returning({}) do |hash|
+ # @git.tags.each do |tag|
+ # hash[tag.sha] ||= []
+ # hash[tag.sha] << tag.name
+ # end
+ # end
+ # # TODO: Patch rails to keep track of what it responds to so we can DRY this up
+ # @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
+ # respond_to do |format|
+ # format.html
+ # format.atom
+ # end
+ # end
+
def tree
@git = Git.bare(@repository.full_repository_path)
@tree = @git.gtree(params[:sha]) |
| |   |
| 1 | module Gitorious |
| 2 | # The point of this class is primary to prevent dangerous/malicious arguments |
| 3 | # to be passed down to the underlying Git library, since it shells out to |
| 4 | # the git binary. |
| 5 | class Gitto |
| 6 | def initialize(repository_path) |
| 7 | @repository_path = repository_path |
| 8 | @git = Git.bare(@repository_path) |
| 9 | end |
| 10 | attr_reader :repository_path, :git |
| 11 | |
| 12 | def log(num, skip=nil) |
| 13 | @git.log(num, skip) |
| 14 | end |
| 15 | |
| 16 | def tree(sha) |
| 17 | check_sha(sha) |
| 18 | @git.gtree(sha) |
| 19 | end |
| 20 | |
| 21 | def commit(sha) |
| 22 | check_sha(sha) |
| 23 | @git.gcommit(sha) |
| 24 | end |
| 25 | |
| 26 | def diff(old_sha, new_sha) |
| 27 | check_sha(old_sha) |
| 28 | check_sha(new_sha) |
| 29 | @git.diff(old_sha, new_sha) |
| 30 | end |
| 31 | |
| 32 | def blob(sha) |
| 33 | check_sha(sha) |
| 34 | @git.gblob(sha) |
| 35 | end |
| 36 | |
| 37 | def branches |
| 38 | @git.branches |
| 39 | end |
| 40 | |
| 41 | def tags |
| 42 | @git.tags |
| 43 | end |
| 44 | |
| 45 | def remotes |
| 46 | @git.remotes |
| 47 | end |
| 48 | |
| 49 | def check_sha(objectish) |
| 50 | if /^[a-z0-9~\{\}\^\.]*$/i !~ objectish.to_s |
| 51 | raise BadShaError |
| 52 | end |
| 53 | end |
| 54 | |
| 55 | class BadShaError < StandardError; end # :nodoc: |
| 56 | end |
| 57 | |
| 58 | end |
| toggle raw diff |
--- /dev/null
+++ b/lib/gitorious/gitto.rb
@@ -0,0 +1,58 @@
+module Gitorious
+ # The point of this class is primary to prevent dangerous/malicious arguments
+ # to be passed down to the underlying Git library, since it shells out to
+ # the git binary.
+ class Gitto
+ def initialize(repository_path)
+ @repository_path = repository_path
+ @git = Git.bare(@repository_path)
+ end
+ attr_reader :repository_path, :git
+
+ def log(num, skip=nil)
+ @git.log(num, skip)
+ end
+
+ def tree(sha)
+ check_sha(sha)
+ @git.gtree(sha)
+ end
+
+ def commit(sha)
+ check_sha(sha)
+ @git.gcommit(sha)
+ end
+
+ def diff(old_sha, new_sha)
+ check_sha(old_sha)
+ check_sha(new_sha)
+ @git.diff(old_sha, new_sha)
+ end
+
+ def blob(sha)
+ check_sha(sha)
+ @git.gblob(sha)
+ end
+
+ def branches
+ @git.branches
+ end
+
+ def tags
+ @git.tags
+ end
+
+ def remotes
+ @git.remotes
+ end
+
+ def check_sha(objectish)
+ if /^[a-z0-9~\{\}\^\.]*$/i !~ objectish.to_s
+ raise BadShaError
+ end
+ end
+
+ class BadShaError < StandardError; end # :nodoc:
+ end
+
+end
\ No newline at end of file |
| |   |
| 0 | | module Gitorious |
| 1 | | module Gitto |
| 2 | | |
| 3 | | class BadShaError < StandardError; end # :nodoc: |
| 4 | | |
| 5 | | # The point of this class is primary to prevent dangerous/malicious arguments |
| 6 | | # to be passed down to the underlying Git library, since it shells out to |
| 7 | | # the git binary. |
| 8 | | class Gitto |
| 9 | | def initialize(repository_path) |
| 10 | | @repository_path = repository_path |
| 11 | | @git = Git.bare(@repository_path) |
| 12 | | end |
| 13 | | attr_reader :repository_path, :git |
| 14 | | |
| 15 | | def log(num, skip=nil) |
| 16 | | @git.log(num, skip) |
| 17 | | end |
| 18 | | |
| 19 | | def tree(sha) |
| 20 | | check_sha(sha) |
| 21 | | @git.gtree(sha) |
| 22 | | end |
| 23 | | |
| 24 | | def commit(sha) |
| 25 | | check_sha(sha) |
| 26 | | @git.gcommit(sha) |
| 27 | | end |
| 28 | | |
| 29 | | def diff(old_sha, new_sha) |
| 30 | | check_sha(old_sha) |
| 31 | | check_sha(new_sha) |
| 32 | | @git.diff(old_sha, new_sha) |
| 33 | | end |
| 34 | | |
| 35 | | def blob(sha) |
| 36 | | check_sha(sha) |
| 37 | | @git.gblob(sha) |
| 38 | | end |
| 39 | | |
| 40 | | def branches |
| 41 | | @git.branches |
| 42 | | end |
| 43 | | |
| 44 | | def tags |
| 45 | | @git.tags |
| 46 | | end |
| 47 | | |
| 48 | | def remotes |
| 49 | | @git.remotes |
| 50 | | end |
| 51 | | |
| 52 | | def check_sha(objectish) |
| 53 | | if /^[a-z0-9~\{\}\^\.]*$/i !~ objectish.to_s |
| 54 | | raise BadShaError |
| 55 | | end |
| 56 | | end |
| 57 | | |
| 58 | | end |
| 59 | | |
| 60 | | end |
| 61 | | end |
| toggle raw diff |
--- a/lib/gitorious/gitto/gitto.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-module Gitorious
- module Gitto
-
- class BadShaError < StandardError; end # :nodoc:
-
- # The point of this class is primary to prevent dangerous/malicious arguments
- # to be passed down to the underlying Git library, since it shells out to
- # the git binary.
- class Gitto
- def initialize(repository_path)
- @repository_path = repository_path
- @git = Git.bare(@repository_path)
- end
- attr_reader :repository_path, :git
-
- def log(num, skip=nil)
- @git.log(num, skip)
- end
-
- def tree(sha)
- check_sha(sha)
- @git.gtree(sha)
- end
-
- def commit(sha)
- check_sha(sha)
- @git.gcommit(sha)
- end
-
- def diff(old_sha, new_sha)
- check_sha(old_sha)
- check_sha(new_sha)
- @git.diff(old_sha, new_sha)
- end
-
- def blob(sha)
- check_sha(sha)
- @git.gblob(sha)
- end
-
- def branches
- @git.branches
- end
-
- def tags
- @git.tags
- end
-
- def remotes
- @git.remotes
- end
-
- def check_sha(objectish)
- if /^[a-z0-9~\{\}\^\.]*$/i !~ objectish.to_s
- raise BadShaError
- end
- end
-
- end
-
- end
-end
\ No newline at end of file |
| |   |
| 1 | 1 | require File.dirname(__FILE__) + '/../spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe BrowseController do |
| 4 | before(:each) do |
| 5 | login_as :johan |
| 6 | @project = projects(:johans) |
| 7 | @repository = @project.repositories.first |
| 8 | |
| 9 | Project.should_receive(:find_by_slug!).with(@project.slug) \ |
| 10 | .and_return(@project) |
| 11 | @project.repositories.should_receive(:find_by_name!) \ |
| 12 | .with(@repository.name).and_return(@repository) |
| 13 | @repository.stub!(:has_commits?).and_return(true) |
| 14 | |
| 15 | @git_mock = mock("Git mock", :null_object => true) |
| 16 | Gitorious::Gitto.should_receive(:new) \ |
| 17 | .with(@repository.full_repository_path) \ |
| 18 | .and_return(@git_mock) |
| 19 | end |
| 20 | |
| 21 | describe "index" do |
| 4 | 22 | |
| 5 | | #Delete this example and add some real ones |
| 6 | | it "should use BrowseController" do |
| 7 | | controller.should be_an_instance_of(BrowseController) |
| 23 | def do_get |
| 24 | get :index, :project_id => @project.slug, :repository_id => @repository.name |
| 25 | end |
| 26 | |
| 27 | it "GETs successfully" do |
| 28 | do_get |
| 29 | flash[:notice].should == nil |
| 30 | response.should be_success |
| 31 | end |
| 32 | |
| 33 | it "fetches the specified log entries" do |
| 34 | @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues")) |
| 35 | do_get |
| 36 | assigns[:commits].should == commits |
| 37 | end |
| 38 | |
| 39 | it "assigns the tags for easy lookup" do |
| 40 | @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues")) |
| 41 | do_get |
| 42 | assigns[:tags_per_sha].should == {:write => "me"} |
| 43 | end |
| 8 | 44 | end |
| 9 | 45 | |
| 10 | 46 | end |
| toggle raw diff |
--- a/spec/controllers/browse_controller_spec.rb
+++ b/spec/controllers/browse_controller_spec.rb
@@ -1,10 +1,46 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe BrowseController do
+ before(:each) do
+ login_as :johan
+ @project = projects(:johans)
+ @repository = @project.repositories.first
+
+ Project.should_receive(:find_by_slug!).with(@project.slug) \
+ .and_return(@project)
+ @project.repositories.should_receive(:find_by_name!) \
+ .with(@repository.name).and_return(@repository)
+ @repository.stub!(:has_commits?).and_return(true)
+
+ @git_mock = mock("Git mock", :null_object => true)
+ Gitorious::Gitto.should_receive(:new) \
+ .with(@repository.full_repository_path) \
+ .and_return(@git_mock)
+ end
+
+ describe "index" do
- #Delete this example and add some real ones
- it "should use BrowseController" do
- controller.should be_an_instance_of(BrowseController)
+ def do_get
+ get :index, :project_id => @project.slug, :repository_id => @repository.name
+ end
+
+ it "GETs successfully" do
+ do_get
+ flash[:notice].should == nil
+ response.should be_success
+ end
+
+ it "fetches the specified log entries" do
+ @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues"))
+ do_get
+ assigns[:commits].should == commits
+ end
+
+ it "assigns the tags for easy lookup" do
+ @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues"))
+ do_get
+ assigns[:tags_per_sha].should == {:write => "me"}
+ end
end
end |
| |   |
| 0 | | require File.dirname(__FILE__) + '/../../../spec_helper' |
| 1 | | |
| 2 | | describe Gitorious::Gitto::Gitto do |
| 3 | | Gitto = Gitorious::Gitto::Gitto |
| 4 | | |
| 5 | | before(:each) do |
| 6 | | @path = "/home/repositories/foo" |
| 7 | | @git_mock = mock("Git mock") |
| 8 | | Git.should_receive(:bare).with(@path).and_return(@git_mock) |
| 9 | | @gitto = Gitto.new(@path) |
| 10 | | end |
| 11 | | |
| 12 | | def some_sha(char = "a") |
| 13 | | char * 40 |
| 14 | | end |
| 15 | | |
| 16 | | it "should return Git#log(10)" do |
| 17 | | @git_mock.should_receive(:log).with(10, nil).and_return([]) |
| 18 | | @gitto.log(10) |
| 19 | | end |
| 20 | | |
| 21 | | it "returns Git#log(10,20)" do |
| 22 | | @git_mock.should_receive(:log).with(10, 20).and_return([]) |
| 23 | | @gitto.log(10, 20) |
| 24 | | end |
| 25 | | |
| 26 | | it "returns Git#gtre" do |
| 27 | | @git_mock.should_receive(:gtree).with(some_sha).and_return(mock("tree")) |
| 28 | | @gitto.should_receive(:check_sha).with(some_sha) |
| 29 | | @gitto.tree(some_sha) |
| 30 | | end |
| 31 | | |
| 32 | | it "return Git#gcommit" do |
| 33 | | @git_mock.should_receive(:gcommit).with(some_sha).and_return(mock("commit")) |
| 34 | | @gitto.should_receive(:check_sha).with(some_sha) |
| 35 | | @gitto.commit(some_sha) |
| 36 | | end |
| 37 | | |
| 38 | | it "return Git#diff" do |
| 39 | | @git_mock.should_receive(:diff).with(some_sha("a"), some_sha("b")).and_return(mock("diff")) |
| 40 | | @gitto.should_receive(:check_sha).with(some_sha("a")) |
| 41 | | @gitto.should_receive(:check_sha).with(some_sha("b")) |
| 42 | | @gitto.diff(some_sha("a"), some_sha("b")) |
| 43 | | end |
| 44 | | |
| 45 | | it "return Git#gblob" do |
| 46 | | @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob")) |
| 47 | | @gitto.should_receive(:check_sha).with(some_sha) |
| 48 | | @gitto.blob(some_sha) |
| 49 | | end |
| 50 | | |
| 51 | | it "return Git#gblob" do |
| 52 | | @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob")) |
| 53 | | @gitto.should_receive(:check_sha).with(some_sha) |
| 54 | | @gitto.blob(some_sha) |
| 55 | | end |
| 56 | | |
| 57 | | it "returns Git#tags" do |
| 58 | | @git_mock.should_receive(:tags).and_return([]) |
| 59 | | @gitto.tags |
| 60 | | end |
| 61 | | |
| 62 | | it "returns Git#branches" do |
| 63 | | @git_mock.should_receive(:branches).and_return([]) |
| 64 | | @gitto.branches |
| 65 | | end |
| 66 | | |
| 67 | | it "returns Git#remotes" do |
| 68 | | @git_mock.should_receive(:remotes).and_return([]) |
| 69 | | @gitto.remotes |
| 70 | | end |
| 71 | | |
| 72 | | describe "objectish validation" do |
| 73 | | it "accepts good objectish" do |
| 74 | | proc{ |
| 75 | | @gitto.check_sha(some_sha) |
| 76 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 77 | | proc{ |
| 78 | | @gitto.check_sha( ("a"*20) + ("2"*20) ) |
| 79 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 80 | | proc{ |
| 81 | | @gitto.check_sha("HEAD") |
| 82 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 83 | | proc{ |
| 84 | | @gitto.check_sha("HEAD~1") |
| 85 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 86 | | proc{ |
| 87 | | @gitto.check_sha("HEAD^{1}") # valid chars at least |
| 88 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 89 | | proc{ |
| 90 | | @gitto.check_sha("v0.1^{tree}") |
| 91 | | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 92 | | end |
| 93 | | |
| 94 | | it "raises on bad objectish" do |
| 95 | | proc{ |
| 96 | | @gitto.check_sha("asd;rm -rf") |
| 97 | | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 98 | | proc{ |
| 99 | | @gitto.check_sha("asd;cat /etc/foo") |
| 100 | | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 101 | | |
| 102 | | proc{ |
| 103 | | @gitto.check_sha("%3B++%2Ffoo") |
| 104 | | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 105 | | end |
| 106 | | end |
| 107 | | |
| 108 | | end |
| toggle raw diff |
--- a/spec/lib/gitorious/gitto/gitto_spec.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe Gitorious::Gitto::Gitto do
- Gitto = Gitorious::Gitto::Gitto
-
- before(:each) do
- @path = "/home/repositories/foo"
- @git_mock = mock("Git mock")
- Git.should_receive(:bare).with(@path).and_return(@git_mock)
- @gitto = Gitto.new(@path)
- end
-
- def some_sha(char = "a")
- char * 40
- end
-
- it "should return Git#log(10)" do
- @git_mock.should_receive(:log).with(10, nil).and_return([])
- @gitto.log(10)
- end
-
- it "returns Git#log(10,20)" do
- @git_mock.should_receive(:log).with(10, 20).and_return([])
- @gitto.log(10, 20)
- end
-
- it "returns Git#gtre" do
- @git_mock.should_receive(:gtree).with(some_sha).and_return(mock("tree"))
- @gitto.should_receive(:check_sha).with(some_sha)
- @gitto.tree(some_sha)
- end
-
- it "return Git#gcommit" do
- @git_mock.should_receive(:gcommit).with(some_sha).and_return(mock("commit"))
- @gitto.should_receive(:check_sha).with(some_sha)
- @gitto.commit(some_sha)
- end
-
- it "return Git#diff" do
- @git_mock.should_receive(:diff).with(some_sha("a"), some_sha("b")).and_return(mock("diff"))
- @gitto.should_receive(:check_sha).with(some_sha("a"))
- @gitto.should_receive(:check_sha).with(some_sha("b"))
- @gitto.diff(some_sha("a"), some_sha("b"))
- end
-
- it "return Git#gblob" do
- @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob"))
- @gitto.should_receive(:check_sha).with(some_sha)
- @gitto.blob(some_sha)
- end
-
- it "return Git#gblob" do
- @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob"))
- @gitto.should_receive(:check_sha).with(some_sha)
- @gitto.blob(some_sha)
- end
-
- it "returns Git#tags" do
- @git_mock.should_receive(:tags).and_return([])
- @gitto.tags
- end
-
- it "returns Git#branches" do
- @git_mock.should_receive(:branches).and_return([])
- @gitto.branches
- end
-
- it "returns Git#remotes" do
- @git_mock.should_receive(:remotes).and_return([])
- @gitto.remotes
- end
-
- describe "objectish validation" do
- it "accepts good objectish" do
- proc{
- @gitto.check_sha(some_sha)
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha( ("a"*20) + ("2"*20) )
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha("HEAD")
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha("HEAD~1")
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha("HEAD^{1}") # valid chars at least
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha("v0.1^{tree}")
- }.should_not raise_error(Gitorious::Gitto::BadShaError)
- end
-
- it "raises on bad objectish" do
- proc{
- @gitto.check_sha("asd;rm -rf")
- }.should raise_error(Gitorious::Gitto::BadShaError)
- proc{
- @gitto.check_sha("asd;cat /etc/foo")
- }.should raise_error(Gitorious::Gitto::BadShaError)
-
- proc{
- @gitto.check_sha("%3B++%2Ffoo")
- }.should raise_error(Gitorious::Gitto::BadShaError)
- end
- end
-
-end
\ No newline at end of file |
| |   |
| 1 | require File.dirname(__FILE__) + '/../../spec_helper' |
| 2 | |
| 3 | describe Gitorious::Gitto do |
| 4 | |
| 5 | before(:each) do |
| 6 | @path = "/home/repositories/foo" |
| 7 | @git_mock = mock("Git mock") |
| 8 | Git.should_receive(:bare).with(@path).and_return(@git_mock) |
| 9 | @gitto = Gitorious::Gitto.new(@path) |
| 10 | end |
| 11 | |
| 12 | def some_sha(char = "a") |
| 13 | char * 40 |
| 14 | end |
| 15 | |
| 16 | it "should return Git#log(10)" do |
| 17 | @git_mock.should_receive(:log).with(10, nil).and_return([]) |
| 18 | @gitto.log(10) |
| 19 | end |
| 20 | |
| 21 | it "returns Git#log(10,20)" do |
| 22 | @git_mock.should_receive(:log).with(10, 20).and_return([]) |
| 23 | @gitto.log(10, 20) |
| 24 | end |
| 25 | |
| 26 | it "returns Git#gtre" do |
| 27 | @git_mock.should_receive(:gtree).with(some_sha).and_return(mock("tree")) |
| 28 | @gitto.should_receive(:check_sha).with(some_sha) |
| 29 | @gitto.tree(some_sha) |
| 30 | end |
| 31 | |
| 32 | it "return Git#gcommit" do |
| 33 | @git_mock.should_receive(:gcommit).with(some_sha).and_return(mock("commit")) |
| 34 | @gitto.should_receive(:check_sha).with(some_sha) |
| 35 | @gitto.commit(some_sha) |
| 36 | end |
| 37 | |
| 38 | it "return Git#diff" do |
| 39 | @git_mock.should_receive(:diff).with(some_sha("a"), some_sha("b")).and_return(mock("diff")) |
| 40 | @gitto.should_receive(:check_sha).with(some_sha("a")) |
| 41 | @gitto.should_receive(:check_sha).with(some_sha("b")) |
| 42 | @gitto.diff(some_sha("a"), some_sha("b")) |
| 43 | end |
| 44 | |
| 45 | it "return Git#gblob" do |
| 46 | @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob")) |
| 47 | @gitto.should_receive(:check_sha).with(some_sha) |
| 48 | @gitto.blob(some_sha) |
| 49 | end |
| 50 | |
| 51 | it "return Git#gblob" do |
| 52 | @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob")) |
| 53 | @gitto.should_receive(:check_sha).with(some_sha) |
| 54 | @gitto.blob(some_sha) |
| 55 | end |
| 56 | |
| 57 | it "returns Git#tags" do |
| 58 | @git_mock.should_receive(:tags).and_return([]) |
| 59 | @gitto.tags |
| 60 | end |
| 61 | |
| 62 | it "returns Git#branches" do |
| 63 | @git_mock.should_receive(:branches).and_return([]) |
| 64 | @gitto.branches |
| 65 | end |
| 66 | |
| 67 | it "returns Git#remotes" do |
| 68 | @git_mock.should_receive(:remotes).and_return([]) |
| 69 | @gitto.remotes |
| 70 | end |
| 71 | |
| 72 | describe "objectish validation" do |
| 73 | it "accepts good objectish" do |
| 74 | proc{ |
| 75 | @gitto.check_sha(some_sha) |
| 76 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 77 | proc{ |
| 78 | @gitto.check_sha( ("a"*20) + ("2"*20) ) |
| 79 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 80 | proc{ |
| 81 | @gitto.check_sha("HEAD") |
| 82 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 83 | proc{ |
| 84 | @gitto.check_sha("HEAD~1") |
| 85 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 86 | proc{ |
| 87 | @gitto.check_sha("HEAD^{1}") # valid chars at least |
| 88 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 89 | proc{ |
| 90 | @gitto.check_sha("v0.1^{tree}") |
| 91 | }.should_not raise_error(Gitorious::Gitto::BadShaError) |
| 92 | end |
| 93 | |
| 94 | it "raises on bad objectish" do |
| 95 | proc{ |
| 96 | @gitto.check_sha("asd;rm -rf") |
| 97 | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 98 | proc{ |
| 99 | @gitto.check_sha("asd;cat /etc/foo") |
| 100 | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 101 | |
| 102 | proc{ |
| 103 | @gitto.check_sha("%3B++%2Ffoo") |
| 104 | }.should raise_error(Gitorious::Gitto::BadShaError) |
| 105 | end |
| 106 | end |
| 107 | |
| 108 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/lib/gitorious/gitto_spec.rb
@@ -0,0 +1,108 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Gitorious::Gitto do
+
+ before(:each) do
+ @path = "/home/repositories/foo"
+ @git_mock = mock("Git mock")
+ Git.should_receive(:bare).with(@path).and_return(@git_mock)
+ @gitto = Gitorious::Gitto.new(@path)
+ end
+
+ def some_sha(char = "a")
+ char * 40
+ end
+
+ it "should return Git#log(10)" do
+ @git_mock.should_receive(:log).with(10, nil).and_return([])
+ @gitto.log(10)
+ end
+
+ it "returns Git#log(10,20)" do
+ @git_mock.should_receive(:log).with(10, 20).and_return([])
+ @gitto.log(10, 20)
+ end
+
+ it "returns Git#gtre" do
+ @git_mock.should_receive(:gtree).with(some_sha).and_return(mock("tree"))
+ @gitto.should_receive(:check_sha).with(some_sha)
+ @gitto.tree(some_sha)
+ end
+
+ it "return Git#gcommit" do
+ @git_mock.should_receive(:gcommit).with(some_sha).and_return(mock("commit"))
+ @gitto.should_receive(:check_sha).with(some_sha)
+ @gitto.commit(some_sha)
+ end
+
+ it "return Git#diff" do
+ @git_mock.should_receive(:diff).with(some_sha("a"), some_sha("b")).and_return(mock("diff"))
+ @gitto.should_receive(:check_sha).with(some_sha("a"))
+ @gitto.should_receive(:check_sha).with(some_sha("b"))
+ @gitto.diff(some_sha("a"), some_sha("b"))
+ end
+
+ it "return Git#gblob" do
+ @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob"))
+ @gitto.should_receive(:check_sha).with(some_sha)
+ @gitto.blob(some_sha)
+ end
+
+ it "return Git#gblob" do
+ @git_mock.should_receive(:gblob).with(some_sha).and_return(mock("blob"))
+ @gitto.should_receive(:check_sha).with(some_sha)
+ @gitto.blob(some_sha)
+ end
+
+ it "returns Git#tags" do
+ @git_mock.should_receive(:tags).and_return([])
+ @gitto.tags
+ end
+
+ it "returns Git#branches" do
+ @git_mock.should_receive(:branches).and_return([])
+ @gitto.branches
+ end
+
+ it "returns Git#remotes" do
+ @git_mock.should_receive(:remotes).and_return([])
+ @gitto.remotes
+ end
+
+ describe "objectish validation" do
+ it "accepts good objectish" do
+ proc{
+ @gitto.check_sha(some_sha)
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha( ("a"*20) + ("2"*20) )
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha("HEAD")
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha("HEAD~1")
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha("HEAD^{1}") # valid chars at least
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha("v0.1^{tree}")
+ }.should_not raise_error(Gitorious::Gitto::BadShaError)
+ end
+
+ it "raises on bad objectish" do
+ proc{
+ @gitto.check_sha("asd;rm -rf")
+ }.should raise_error(Gitorious::Gitto::BadShaError)
+ proc{
+ @gitto.check_sha("asd;cat /etc/foo")
+ }.should raise_error(Gitorious::Gitto::BadShaError)
+
+ proc{
+ @gitto.check_sha("%3B++%2Ffoo")
+ }.should raise_error(Gitorious::Gitto::BadShaError)
+ end
+ end
+
+end
\ No newline at end of file |