summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-02-18 21:45:51 -0800
committerStan Hu <stanhu@gmail.com>2018-02-18 21:48:49 -0800
commit8d32dfef9b7eefe3d48dc63398315ba41879329c (patch)
tree1b42dbc18144454d1c9e8e7708806cb2cbd7e437 /spec
parent557db7e635c70bf68a15f7029014301013b30070 (diff)
downloadgitlab-ce-sh-fix-squash-rebase-utf8-data.tar.gz
Fix squash rebase not working when diff contained encoded datash-fix-squash-rebase-utf8-data
When the applied diff contains UTF-8 or some other encoded data, the diff returned back from the git process may be in ASCII-8BIT format. Writing this data to stdin may fail if the data because stdin expects this data to be in UTF-8. By switching the output to binmode, we ensure that the diff will always be written as-is. Closes gitlab-org/gitlab-ee#4960
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index edcf8889c27..0e9150964fa 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require "spec_helper"
describe Gitlab::Git::Repository, seed_helper: true do
@@ -2221,6 +2222,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
subject
end
end
+
+ context 'with an ASCII-8BIT diff', :skip_gitaly_mock do
+ let(:diff) { "diff --git a/README.md b/README.md\nindex faaf198..43c5edf 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-testme\n+✓ testme\n ======\n \n Sample repo for testing gitlab features\n" }
+
+ it 'applies a ASCII-8BIT diff' do
+ allow(repository).to receive(:run_git!).and_call_original
+ allow(repository).to receive(:run_git!).with(%W(diff --binary #{start_sha}...#{end_sha})).and_return(diff.force_encoding('ASCII-8BIT'))
+
+ expect(subject.length).to eq(40)
+ end
+ end
end
end