Commit 0f721fe3 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'zj-gitaly-encoding-issue' into 'master'

Encode revision for gitattributes ref

Closes gitaly#1032 and #43278

See merge request gitlab-org/gitlab-ce!17291
parents e20f96c8 c12b18c5
---
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,12 +1406,35 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1406,12 +1406,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
describe "#copy_gitattributes" do describe "#copy_gitattributes" do
shared_examples 'applying git attributes' do
let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') } let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') }
after do
FileUtils.rm_rf(attributes_path) if Dir.exist?(attributes_path)
end
it "raises an error with invalid ref" do it "raises an error with invalid ref" do
expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef) expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef)
end end
context 'when forcing encoding issues' do
let(:branch_name) { "ʕ•ᴥ•ʔ" }
before do
repository.create_branch(branch_name, "master")
end
after do
repository.rm_branch(branch_name, user: build(:admin))
end
it "doesn't raise with a valid unicode ref" do
expect { repository.copy_gitattributes(branch_name) }.not_to raise_error
repository
end
end
context "with no .gitattrbutes" do context "with no .gitattrbutes" do
before do before do
repository.copy_gitattributes("master") repository.copy_gitattributes("master")
...@@ -1420,10 +1443,6 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1420,10 +1443,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
it "does not have an info/attributes" do it "does not have an info/attributes" do
expect(File.exist?(attributes_path)).to be_falsey expect(File.exist?(attributes_path)).to be_falsey
end end
after do
FileUtils.rm_rf(attributes_path)
end
end end
context "with .gitattrbutes" do context "with .gitattrbutes" do
...@@ -1439,10 +1458,6 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1439,10 +1458,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
contents = File.open(attributes_path, "rb") { |f| f.read } contents = File.open(attributes_path, "rb") { |f| f.read }
expect(contents).to eq("*.md binary\n") expect(contents).to eq("*.md binary\n")
end end
after do
FileUtils.rm_rf(attributes_path)
end
end end
context "with updated .gitattrbutes" do context "with updated .gitattrbutes" do
...@@ -1459,10 +1474,6 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1459,10 +1474,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
contents = File.read(attributes_path) contents = File.read(attributes_path)
expect(contents).to eq("*.txt binary\n") expect(contents).to eq("*.txt binary\n")
end end
after do
FileUtils.rm_rf(attributes_path)
end
end end
context "with no .gitattrbutes in HEAD but with previous info/attributes" do context "with no .gitattrbutes in HEAD but with previous info/attributes" do
...@@ -1474,10 +1485,15 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1474,10 +1485,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
it "does not have an info/attributes" do it "does not have an info/attributes" do
expect(File.exist?(attributes_path)).to be_falsey expect(File.exist?(attributes_path)).to be_falsey
end end
end
end
after do context 'when gitaly is enabled' do
FileUtils.rm_rf(attributes_path) it_behaves_like 'applying git attributes'
end end
context 'when gitaly is disabled', :disable_gitaly do
it_behaves_like 'applying git attributes'
end end
end end
......
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