Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.sshd.commands; 16 : 17 : import com.google.gerrit.extensions.api.GerritApi; 18 : import com.google.gerrit.extensions.api.projects.BranchInput; 19 : import com.google.gerrit.extensions.restapi.RestApiException; 20 : import com.google.gerrit.server.project.ProjectState; 21 : import com.google.gerrit.sshd.CommandMetaData; 22 : import com.google.gerrit.sshd.SshCommand; 23 : import com.google.inject.Inject; 24 : import org.kohsuke.args4j.Argument; 25 : 26 : /** Create a new branch. * */ 27 : @CommandMetaData(name = "create-branch", description = "Create a new branch") 28 1 : public final class CreateBranchCommand extends SshCommand { 29 : 30 : @Argument(index = 0, required = true, metaVar = "PROJECT", usage = "name of the project") 31 : private ProjectState project; 32 : 33 : @Argument(index = 1, required = true, metaVar = "NAME", usage = "name of branch to be created") 34 : private String name; 35 : 36 : @Argument( 37 : index = 2, 38 : required = true, 39 : metaVar = "REVISION", 40 : usage = "base revision of the new branch") 41 : private String revision; 42 : 43 : @Inject GerritApi gApi; 44 : 45 : @Override 46 : protected void run() throws UnloggedFailure { 47 0 : enableGracefulStop(); 48 : try { 49 0 : BranchInput in = new BranchInput(); 50 0 : in.revision = revision; 51 0 : gApi.projects().name(project.getName()).branch(name).create(in); 52 0 : } catch (RestApiException e) { 53 0 : throw die(e); 54 0 : } 55 0 : } 56 : }