Skip to content
Snippets Groups Projects
Commit d2bdcf7a authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'file-permissions' into 'master'

gives same permissions to file even if the file was renamed

Used to fix https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5979

See merge request !118
parents 4832ec2c 0f258836
No related branches found
No related tags found
1 merge request!118gives same permissions to file even if the file was renamed
Pipeline #
v 10.6.5
- Retain file mode whenever file is renamed
v 10.6.4
- Diff sizes are now checked before loading any extra data into memory
 
Loading
Loading
Loading
Loading
@@ -44,6 +44,10 @@ GitLab Git used grit as main library in past. Now it uses rugged
# Access to rugged repo object
repo.rugged
 
### Specs
In case it's needed to update https://gitlab.com/gitlab-org/gitlab-git-test with new content changes the developer should update `spec/support/last_commit.rb` with the updated sha of the last commit and the required information. The developer should also run the full set of tests to check which ones are failing and fix them accordingly.
### Tree
 
# Tree objects for root dir
Loading
Loading
Loading
Loading
@@ -131,6 +131,7 @@ module Gitlab
ref = commit[:branch]
update_ref = commit[:update_ref].nil? ? true : commit[:update_ref]
parents = []
mode = 0o100644
 
unless ref.start_with?('refs/')
ref = 'refs/heads/' + ref
Loading
Loading
@@ -154,17 +155,18 @@ module Gitlab
if action == :remove
index.remove(filename)
else
file_entry = index.get(filename)
if action == :rename
old_path_name = PathHelper.normalize_path(file[:previous_path])
old_filename = old_path_name.to_s
index.remove(old_filename)
file_entry = index.get(old_filename)
index.remove(old_filename) unless file_entry.blank?
end
 
mode = 0o100644
file_entry = index.get(filename)
if file_entry
raise Repository::InvalidBlobName.new("Filename already exists; update not allowed") unless update
# Preserve the current file mode if one is available
mode = file_entry[:mode] if file_entry[:mode]
end
Loading
Loading
Loading
Loading
@@ -300,12 +300,11 @@ describe Gitlab::Git::Blob do
 
describe :rename do
let(:repository) { Gitlab::Git::Repository.new(TEST_NORMAL_REPO_PATH) }
let(:commit_options) do
let(:rename_options) do
options = {
file: {
path: 'NEWREADME.md',
previous_path: 'README.md',
path: 'NEWCONTRIBUTING.md',
previous_path: 'CONTRIBUTING.md',
content: 'Lorem ipsum...',
update: true
},
Loading
Loading
@@ -326,26 +325,47 @@ describe Gitlab::Git::Blob do
}
end
 
let!(:ref) { commit_options[:commit][:branch] }
let!(:prev_commit_count) { repository.commit_count(ref) }
let(:commit_sha) { Gitlab::Git::Blob.rename(repository, commit_options) }
let(:commit_count) { repository.commit_count(ref) }
let(:commit) { repository.lookup(commit_sha) }
let(:blob) { Gitlab::Git::Blob.find(repository, commit_sha, "NEWREADME.md") }
let(:removed_blob) { Gitlab::Git::Blob.find(repository, commit_sha, "README.md") }
let(:rename_options2) do
options = {
file: {
content: 'Lorem ipsum...',
path: 'bin/new_executable',
previous_path: 'bin/executable',
},
author: {
email: 'user@example.com',
name: 'Test User',
time: Time.now
},
committer: {
email: 'user@example.com',
name: 'Test User',
time: Time.now
},
commit: {
message: 'Updates toberenamed.txt',
branch: 'master',
update_ref: false
}
}
end
 
it 'should rename the file with commit' do
# Commit message valid
expect(commit.message).to eq('Rename readme')
it 'maintains file permissions when renaming' do
mode = 0o100755
Gitlab::Git::Blob.rename(repository, rename_options2)
expect(repository.rugged.index.get(rename_options2[:file][:path])[:mode]).to eq(mode)
end
 
# Only one commit was made
expect(commit_count).to eq(prev_commit_count + 1)
it 'renames the file with commit and not change file permissions' do
ref = rename_options[:commit][:branch]
 
# Previous file was removed
expect(removed_blob).to be_nil
expect(repository.rugged.index.get('CONTRIBUTING.md')).not_to be_nil
expect { Gitlab::Git::Blob.rename(repository, rename_options) }.to change { repository.commit_count(ref) }.by(1)
 
# File was renamed
expect(blob).not_to be_nil
expect(repository.rugged.index.get('CONTRIBUTING.md')).to be_nil
expect(repository.rugged.index.get('NEWCONTRIBUTING.md')).not_to be_nil
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment