Commit c12b18c5 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Encode revision for gitattributes ref

A field didn't call the needed encoding helper, thus some UTF-8 encoding
couldn't be encoded to ASCII. Using the helper method this was fixed.

Tests are now run against Gitaly and Rugged too, to ensure both remain
working correctly.

Fixes gitlab-org/gitaly#1032, gitlab-org/gitlab-ce#43278
parent 71545ca6
---
title: Encode branch name as binary before creating a RPC request to copy attributes
merge_request: 17291
author:
type: fixed
...@@ -41,7 +41,7 @@ module Gitlab ...@@ -41,7 +41,7 @@ module Gitlab
end end
def apply_gitattributes(revision) def apply_gitattributes(revision)
request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: revision) request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: encode_binary(revision))
GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request) GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request)
end end
......
...@@ -1406,79 +1406,95 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1406,79 +1406,95 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
describe "#copy_gitattributes" do describe "#copy_gitattributes" do
let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') } shared_examples 'applying git attributes' do
let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') }
it "raises an error with invalid ref" do after do
expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef) FileUtils.rm_rf(attributes_path) if Dir.exist?(attributes_path)
end
context "with no .gitattrbutes" do
before do
repository.copy_gitattributes("master")
end end
it "does not have an info/attributes" do it "raises an error with invalid ref" do
expect(File.exist?(attributes_path)).to be_falsey expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef)
end end
after do context 'when forcing encoding issues' do
FileUtils.rm_rf(attributes_path) let(:branch_name) { "ʕ•ᴥ•ʔ" }
end
end
context "with .gitattrbutes" do before do
before do repository.create_branch(branch_name, "master")
repository.copy_gitattributes("gitattributes") end
end
it "has an info/attributes" do after do
expect(File.exist?(attributes_path)).to be_truthy repository.rm_branch(branch_name, user: build(:admin))
end end
it "has the same content in info/attributes as .gitattributes" do it "doesn't raise with a valid unicode ref" do
contents = File.open(attributes_path, "rb") { |f| f.read } expect { repository.copy_gitattributes(branch_name) }.not_to raise_error
expect(contents).to eq("*.md binary\n")
end
after do repository
FileUtils.rm_rf(attributes_path) end
end end
end
context "with updated .gitattrbutes" do context "with no .gitattrbutes" do
before do before do
repository.copy_gitattributes("gitattributes") repository.copy_gitattributes("master")
repository.copy_gitattributes("gitattributes-updated") end
end
it "has an info/attributes" do it "does not have an info/attributes" do
expect(File.exist?(attributes_path)).to be_truthy expect(File.exist?(attributes_path)).to be_falsey
end
end end
it "has the updated content in info/attributes" do context "with .gitattrbutes" do
contents = File.read(attributes_path) before do
expect(contents).to eq("*.txt binary\n") repository.copy_gitattributes("gitattributes")
end end
after do it "has an info/attributes" do
FileUtils.rm_rf(attributes_path) expect(File.exist?(attributes_path)).to be_truthy
end end
end
context "with no .gitattrbutes in HEAD but with previous info/attributes" do it "has the same content in info/attributes as .gitattributes" do
before do contents = File.open(attributes_path, "rb") { |f| f.read }
repository.copy_gitattributes("gitattributes") expect(contents).to eq("*.md binary\n")
repository.copy_gitattributes("master") end
end end
it "does not have an info/attributes" do context "with updated .gitattrbutes" do
expect(File.exist?(attributes_path)).to be_falsey before do
repository.copy_gitattributes("gitattributes")
repository.copy_gitattributes("gitattributes-updated")
end
it "has an info/attributes" do
expect(File.exist?(attributes_path)).to be_truthy
end
it "has the updated content in info/attributes" do
contents = File.read(attributes_path)
expect(contents).to eq("*.txt binary\n")
end
end end
after do context "with no .gitattrbutes in HEAD but with previous info/attributes" do
FileUtils.rm_rf(attributes_path) before do
repository.copy_gitattributes("gitattributes")
repository.copy_gitattributes("master")
end
it "does not have an info/attributes" do
expect(File.exist?(attributes_path)).to be_falsey
end
end end
end end
context 'when gitaly is enabled' do
it_behaves_like 'applying git attributes'
end
context 'when gitaly is disabled', :disable_gitaly do
it_behaves_like 'applying git attributes'
end
end end
describe '#ref_exists?' do describe '#ref_exists?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment