Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
3ac54d22
Commit
3ac54d22
authored
Feb 28, 2017
by
Mark Fletcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure archive download is only one directory deep
parent
7733f285
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
17 deletions
+39
-17
changelogs/unreleased/28805-download-archive-with-branch-like-feature-xxxx-add-extra-directory-level.yml
...th-branch-like-feature-xxxx-add-extra-directory-level.yml
+4
-0
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+6
-2
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+29
-15
No files found.
changelogs/unreleased/28805-download-archive-with-branch-like-feature-xxxx-add-extra-directory-level.yml
0 → 100644
View file @
3ac54d22
---
title
:
Ensure archive download is only one directory deep
merge_request
:
9616
author
:
lib/gitlab/git/repository.rb
View file @
3ac54d22
...
@@ -199,13 +199,17 @@ module Gitlab
...
@@ -199,13 +199,17 @@ module Gitlab
nil
nil
end
end
def
archive_prefix
(
ref
,
sha
)
project_name
=
self
.
name
.
chomp
(
'.git'
)
"
#{
project_name
}
-
#{
ref
.
parameterize
}
-
#{
sha
}
"
end
def
archive_metadata
(
ref
,
storage_path
,
format
=
"tar.gz"
)
def
archive_metadata
(
ref
,
storage_path
,
format
=
"tar.gz"
)
ref
||=
root_ref
ref
||=
root_ref
commit
=
Gitlab
::
Git
::
Commit
.
find
(
self
,
ref
)
commit
=
Gitlab
::
Git
::
Commit
.
find
(
self
,
ref
)
return
{}
if
commit
.
nil?
return
{}
if
commit
.
nil?
project_name
=
self
.
name
.
chomp
(
'.git'
)
prefix
=
archive_prefix
(
ref
,
commit
.
id
)
prefix
=
"
#{
project_name
}
-
#{
ref
}
-
#{
commit
.
id
}
"
{
{
'RepoPath'
=>
path
,
'RepoPath'
=>
path
,
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
3ac54d22
...
@@ -47,7 +47,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -47,7 +47,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
:branch_names
do
describe
'#branch_names'
do
subject
{
repository
.
branch_names
}
subject
{
repository
.
branch_names
}
it
'has SeedRepo::Repo::BRANCHES.size elements'
do
it
'has SeedRepo::Repo::BRANCHES.size elements'
do
...
@@ -57,7 +57,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -57,7 +57,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
it
{
is_expected
.
not_to
include
(
"branch-from-space"
)
}
it
{
is_expected
.
not_to
include
(
"branch-from-space"
)
}
end
end
describe
:tag_names
do
describe
'#tag_names'
do
subject
{
repository
.
tag_names
}
subject
{
repository
.
tag_names
}
it
{
is_expected
.
to
be_kind_of
Array
}
it
{
is_expected
.
to
be_kind_of
Array
}
...
@@ -78,49 +78,63 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -78,49 +78,63 @@ describe Gitlab::Git::Repository, seed_helper: true do
it
{
expect
(
metadata
[
'ArchivePath'
]).
to
end_with
extenstion
}
it
{
expect
(
metadata
[
'ArchivePath'
]).
to
end_with
extenstion
}
end
end
describe
:archive
do
describe
'#archive_prefix'
do
let
(
:project_name
)
{
'project-name'
}
before
do
expect
(
repository
).
to
receive
(
:name
).
once
.
and_return
(
project_name
)
end
it
'returns parameterised string for a ref containing slashes'
do
prefix
=
repository
.
archive_prefix
(
'test/branch'
,
'SHA'
)
expect
(
prefix
).
to
eq
(
"
#{
project_name
}
-test-branch-SHA"
)
end
end
describe
'#archive'
do
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
)
}
it_should_behave_like
'archive check'
,
'.tar.gz'
it_should_behave_like
'archive check'
,
'.tar.gz'
end
end
describe
:archive_zip
do
describe
'#archive_zip'
do
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'zip'
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'zip'
)
}
it_should_behave_like
'archive check'
,
'.zip'
it_should_behave_like
'archive check'
,
'.zip'
end
end
describe
:archive_bz2
do
describe
'#archive_bz2'
do
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'tbz2'
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'tbz2'
)
}
it_should_behave_like
'archive check'
,
'.tar.bz2'
it_should_behave_like
'archive check'
,
'.tar.bz2'
end
end
describe
:archive_fallback
do
describe
'#archive_fallback'
do
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'madeup'
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
'master'
,
'/tmp'
,
'madeup'
)
}
it_should_behave_like
'archive check'
,
'.tar.gz'
it_should_behave_like
'archive check'
,
'.tar.gz'
end
end
describe
:size
do
describe
'#size'
do
subject
{
repository
.
size
}
subject
{
repository
.
size
}
it
{
is_expected
.
to
be
<
2
}
it
{
is_expected
.
to
be
<
2
}
end
end
describe
:has_commits?
do
describe
'#has_commits?'
do
it
{
expect
(
repository
.
has_commits?
).
to
be_truthy
}
it
{
expect
(
repository
.
has_commits?
).
to
be_truthy
}
end
end
describe
:empty?
do
describe
'#empty?'
do
it
{
expect
(
repository
.
empty?
).
to
be_falsey
}
it
{
expect
(
repository
.
empty?
).
to
be_falsey
}
end
end
describe
:bare?
do
describe
'#bare?'
do
it
{
expect
(
repository
.
bare?
).
to
be_truthy
}
it
{
expect
(
repository
.
bare?
).
to
be_truthy
}
end
end
describe
:heads
do
describe
'#heads'
do
let
(
:heads
)
{
repository
.
heads
}
let
(
:heads
)
{
repository
.
heads
}
subject
{
heads
}
subject
{
heads
}
...
@@ -147,7 +161,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -147,7 +161,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
:ref_names
do
describe
'#ref_names'
do
let
(
:ref_names
)
{
repository
.
ref_names
}
let
(
:ref_names
)
{
repository
.
ref_names
}
subject
{
ref_names
}
subject
{
ref_names
}
...
@@ -164,7 +178,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -164,7 +178,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
:search_files
do
describe
'#search_files'
do
let
(
:results
)
{
repository
.
search_files
(
'rails'
,
'master'
)
}
let
(
:results
)
{
repository
.
search_files
(
'rails'
,
'master'
)
}
subject
{
results
}
subject
{
results
}
...
@@ -200,7 +214,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -200,7 +214,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
context
:submodules
do
context
'#submodules'
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
TEST_REPO_PATH
)
}
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
TEST_REPO_PATH
)
}
context
'where repo has submodules'
do
context
'where repo has submodules'
do
...
@@ -264,7 +278,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -264,7 +278,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
:commit_count
do
describe
'#commit_count'
do
it
{
expect
(
repository
.
commit_count
(
"master"
)).
to
eq
(
25
)
}
it
{
expect
(
repository
.
commit_count
(
"master"
)).
to
eq
(
25
)
}
it
{
expect
(
repository
.
commit_count
(
"feature"
)).
to
eq
(
9
)
}
it
{
expect
(
repository
.
commit_count
(
"feature"
)).
to
eq
(
9
)
}
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment