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
Tatuya Kamada
gitlab-ce
Commits
3e47ea50
Commit
3e47ea50
authored
Jan 26, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Files::CreateService can now commit file to empty repository
parent
ff7055ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
app/services/files/create_service.rb
app/services/files/create_service.rb
+12
-7
lib/gitlab/satellite/files/new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+9
-3
No files found.
app/services/files/create_service.rb
View file @
3e47ea50
...
...
@@ -9,10 +9,6 @@ module Files
return
error
(
"You are not allowed to create file in this branch"
)
end
unless
repository
.
branch_names
.
include?
(
ref
)
return
error
(
"You can only create files if you are on top of a branch"
)
end
file_name
=
File
.
basename
(
path
)
file_path
=
path
...
...
@@ -23,12 +19,21 @@ module Files
)
end
blob
=
repository
.
blob_at_branch
(
ref
,
file_path
)
if
project
.
empty_repo?
# everything is ok because repo does not have a commits yet
else
unless
repository
.
branch_names
.
include?
(
ref
)
return
error
(
"You can only create files if you are on top of a branch"
)
end
if
blob
return
error
(
"Your changes could not be committed, because file with such name exists"
)
blob
=
repository
.
blob_at_branch
(
ref
,
file_path
)
if
blob
return
error
(
"Your changes could not be committed, because file with such name exists"
)
end
end
new_file_action
=
Gitlab
::
Satellite
::
NewFileAction
.
new
(
current_user
,
project
,
ref
,
file_path
)
created_successfully
=
new_file_action
.
commit!
(
params
[
:content
],
...
...
lib/gitlab/satellite/files/new_file_action.rb
View file @
3e47ea50
...
...
@@ -14,7 +14,14 @@ module Gitlab
prepare_satellite!
(
repo
)
# create target branch in satellite at the corresponding commit from bare repo
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
current_ref
=
if
repo
.
commits
.
any?
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
ref
else
# skip this step if we want to add first file to empty repo
Satellite
::
PARKING_BRANCH
end
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
dir_name_in_satellite
=
File
.
dirname
(
file_path_in_satellite
)
...
...
@@ -38,10 +45,9 @@ module Gitlab
# will raise CommandFailed when commit fails
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
# push commit back to bare repo
# will raise CommandFailed when push fails
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
ref
)
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
"
#{
current_ref
}
:
#{
ref
}
"
)
# everything worked
true
...
...
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