Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-01-27 02:36:57 +0300
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-01-27 02:36:57 +0300
commit2b050601499bad178bc9ecd3aa0a4ce5141b40c4 (patch)
tree278c629ca37a0460dfac76353a60fb495dc18338
parentff7055eef30ac6e770166728443c22b88e07f561 (diff)
parent6a2384e0bc7d0b703c8f6af144c85af47eae6630 (diff)
Merge branch 'init-from-ui' into 'master'
Create first file from empty repository via UI. pt1 * Backend can now commit file to empty repository. * Empty project UI has new file button First step in building #1930 See merge request !1438
-rw-r--r--app/assets/stylesheets/generic/buttons.scss5
-rw-r--r--app/services/files/create_service.rb19
-rw-r--r--app/views/projects/empty.html.haml11
-rw-r--r--lib/gitlab/satellite/files/new_file_action.rb12
4 files changed, 37 insertions, 10 deletions
diff --git a/app/assets/stylesheets/generic/buttons.scss b/app/assets/stylesheets/generic/buttons.scss
index d098f1ecaa2..3b360275065 100644
--- a/app/assets/stylesheets/generic/buttons.scss
+++ b/app/assets/stylesheets/generic/buttons.scss
@@ -173,6 +173,11 @@
margin-right: 0px;
}
}
+
+ &.btn-lg {
+ font-size: 15px;
+ line-height: 1.4;
+ }
}
.btn-block {
diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb
index b90adeef00a..2c457ef2cef 100644
--- a/app/services/files/create_service.rb
+++ b/app/services/files/create_service.rb
@@ -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],
diff --git a/app/views/projects/empty.html.haml b/app/views/projects/empty.html.haml
index 2e46de6bfe0..3a42fce43e9 100644
--- a/app/views/projects/empty.html.haml
+++ b/app/views/projects/empty.html.haml
@@ -3,6 +3,17 @@
= render "home_panel"
+.center.well
+ %h3
+ The repository for this project is empty
+ %p.lead
+ You can
+ = link_to '#', class: 'btn btn-new btn-lg' do
+ add a file
+ &nbsp;or push it via command line.
+
+%h4
+ %strong Command line instructions
%div.git-empty
%fieldset
%legend Git global setup
diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb
index 15e9b7a6f77..c230239d390 100644
--- a/lib/gitlab/satellite/files/new_file_action.rb
+++ b/lib/gitlab/satellite/files/new_file_action.rb
@@ -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