Created
April 12, 2013 06:48
-
-
Save gnurag/5369986 to your computer and use it in GitHub Desktop.
Experiment to study Grit's behavior on a readonly filesystem.
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
#!/usr/bin/env ruby | |
require 'grit' | |
require 'test/unit' | |
REPO_PATH = ARGV[0] | |
if ARGV.empty? | |
puts "Usage: test_rogit.rb [PATH_TO_GIT_REPO]" | |
exit | |
else | |
$repo = Grit::Repo.new(REPO_PATH) | |
end | |
class TestRoGit < Test::Unit::TestCase | |
# Test if the git repo object got initialized. | |
def test_repo_path | |
rpath = $repo.bare ? REPO_PATH : REPO_PATH + "/.git" | |
assert_equal(rpath, $repo.path) | |
end | |
# For all the Branch HEADs, Tags & Commit IDs, look for the first | |
# file Blob in the commit tree and assert the equality of the size | |
# of its contents against the size reported by Grit::Blob.size | |
# | |
# The idea is to see if Grit is able to fetch file's contents from | |
# across the commit-ids, tags when mounted on a RW or RO filesystem. | |
def test_commit_data | |
commit_list = ['HEAD'] | |
# Add all the branches to the commit list | |
$repo.branches.each{|branch| | |
commit_list << branch.name | |
# Add all the commit-ids from this branch to the commit list | |
$repo.commits(branch.name, 10000).each{|c| commit_list << c.id} | |
} | |
# Add all the tags to the commit list | |
$repo.tags.each{|t| commit_list << t.name} | |
# Run assertions for all the commit ids collected. | |
commit_list.each{|commit| | |
tree = $repo.commits(commit).first.tree | |
if tree.contents.first.class == Grit::Blob | |
blob = tree.contents.first | |
assert_equal(blob.size, blob.data.length) | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment