Repository#blob_at_branch

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-02-05 11:39:55 +02:00
parent d701d58695
commit 55572c4e86
No known key found for this signature in database
GPG Key ID: 627C5F589F467F17
4 changed files with 13 additions and 6 deletions

View File

@ -178,4 +178,14 @@ class Repository
Tree.new(self, sha, path) Tree.new(self, sha, path)
end end
def blob_at_branch(branch_name, path)
last_commit = commit(branch_name)
if last_commit
blob_at(last_commit.sha, path)
else
nil
end
end
end end

View File

@ -24,8 +24,7 @@ module Files
return error("Your changes could not be committed, because file name contains not allowed characters") return error("Your changes could not be committed, because file name contains not allowed characters")
end end
commit = repository.commit(ref) blob = repository.blob_at_branch(ref, file_path)
blob = repository.blob_at(commit.sha, file_path)
if blob if blob
return error("Your changes could not be committed, because file with such name exists") return error("Your changes could not be committed, because file with such name exists")

View File

@ -17,8 +17,7 @@ module Files
return error("You can only create files if you are on top of a branch") return error("You can only create files if you are on top of a branch")
end end
commit = repository.commit(ref) blob = repository.blob_at_branch(ref, path)
blob = repository.blob_at(commit.sha, path)
unless blob unless blob
return error("You can only edit text files") return error("You can only edit text files")

View File

@ -17,8 +17,7 @@ module Files
return error("You can only create files if you are on top of a branch") return error("You can only create files if you are on top of a branch")
end end
commit = repository.commit(ref) blob = repository.blob_at_branch(ref, path)
blob = repository.blob_at(commit.sha, path)
unless blob unless blob
return error("You can only edit text files") return error("You can only edit text files")