summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-02-19 15:11:10 +0000
committerSean McGivern <sean@gitlab.com>2018-02-19 15:11:10 +0000
commit01f5035bfe2c2fa6cc71564e8a02fbcb325e3370 (patch)
tree6324c9da14c4e7e6438c36ddc3729b50c82e7117
parent0b032daa11d5ea140f2eea99fa10b21da4b50f0b (diff)
downloadgitlab-ce-fix-squash-with-renamed-files.tar.gz
Fix squash with renamed filesfix-squash-with-renamed-files
We need to ignore the names for renamed files when configuring with sparse checkout.
-rw-r--r--changelogs/unreleased/fix-squash-with-renamed-files.yml5
-rw-r--r--lib/gitlab/git/repository.rb2
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb31
3 files changed, 33 insertions, 5 deletions
diff --git a/changelogs/unreleased/fix-squash-with-renamed-files.yml b/changelogs/unreleased/fix-squash-with-renamed-files.yml
new file mode 100644
index 00000000000..f7cd3a84367
--- /dev/null
+++ b/changelogs/unreleased/fix-squash-with-renamed-files.yml
@@ -0,0 +1,5 @@
+---
+title: Fix squashing when a file is renamed
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index a10bc0dd32b..4261f028d35 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -2188,7 +2188,7 @@ module Gitlab
)
diff_range = "#{start_sha}...#{end_sha}"
diff_files = run_git!(
- %W(diff --name-only --diff-filter=a --binary #{diff_range})
+ %W(diff --name-only --diff-filter=ar --binary #{diff_range})
).chomp
with_worktree(squash_path, branch, sparse_checkout_files: diff_files, env: env) do
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 0e9150964fa..0482c48bde8 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -2204,7 +2204,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'sparse checkout', :skip_gitaly_mock do
let(:expected_files) { %w(files files/js files/js/application.js) }
- before do
+ it 'checks out only the files in the diff' do
allow(repository).to receive(:with_worktree).and_wrap_original do |m, *args|
m.call(*args) do
worktree_path = args[0]
@@ -2216,11 +2216,34 @@ describe Gitlab::Git::Repository, seed_helper: true do
expect(Dir[files_pattern]).to eq(expected)
end
end
- end
- it 'checkouts only the files in the diff' do
subject
end
+
+ context 'when the diff contains a rename' do
+ let(:repo) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged }
+ let(:end_sha) { new_commit_move_file(repo).oid }
+
+ after do
+ # Erase our commits so other tests get the original repo
+ repo = Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged
+ repo.references.update('refs/heads/master', SeedRepo::LastCommit::ID)
+ end
+
+ it 'does not include the renamed file in the sparse checkout' do
+ allow(repository).to receive(:with_worktree).and_wrap_original do |m, *args|
+ m.call(*args) do
+ worktree_path = args[0]
+ files_pattern = File.join(worktree_path, '**', '*')
+
+ expect(Dir[files_pattern]).not_to include('CHANGELOG')
+ expect(Dir[files_pattern]).not_to include('encoding/CHANGELOG')
+ end
+ end
+
+ subject
+ end
+ end
end
context 'with an ASCII-8BIT diff', :skip_gitaly_mock do
@@ -2230,7 +2253,7 @@ describe Gitlab::Git::Repository, seed_helper: true 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)
+ expect(subject).to match(/\h{40}/)
end
end
end