Merge branch 'fix-squash-with-renamed-files' into 'master'
Fix squash with renamed files Closes gitlab-ee#4975 See merge request gitlab-org/gitlab-ce!17216
This commit is contained in:
commit
eb421c88ee
3 changed files with 33 additions and 5 deletions
5
changelogs/unreleased/fix-squash-with-renamed-files.yml
Normal file
5
changelogs/unreleased/fix-squash-with-renamed-files.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix squashing when a file is renamed
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -2200,7 +2200,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
|
||||
|
|
|
@ -2231,7 +2231,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]
|
||||
|
@ -2243,12 +2243,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
|
|||
expect(Dir[files_pattern]).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it 'checkouts only the files in the diff' do
|
||||
subject
|
||||
end
|
||||
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" }
|
||||
|
@ -2257,7 +2280,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
|
||||
|
|
Loading…
Reference in a new issue