573efabf7cab33d883030deae050121fe8355af5
[teamcity/git-plugin.git] / git-agent / src / jetbrains / buildServer / buildTriggers / vcs / git / agent / command / impl / GetConfigCommandImpl.java
1 /*
2  * Copyright 2000-2018 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package jetbrains.buildServer.buildTriggers.vcs.git.agent.command.impl;
18
19 import jetbrains.buildServer.ExecResult;
20 import jetbrains.buildServer.buildTriggers.vcs.git.agent.GitCommandLine;
21 import jetbrains.buildServer.buildTriggers.vcs.git.agent.command.GetConfigCommand;
22 import jetbrains.buildServer.vcs.VcsException;
23 import org.jetbrains.annotations.NotNull;
24
25 public class GetConfigCommandImpl extends BaseCommandImpl implements GetConfigCommand {
26
27   private String myName;
28
29   public GetConfigCommandImpl(@NotNull GitCommandLine cmd) {
30     super(cmd);
31   }
32
33   @NotNull
34   public GetConfigCommand setPropertyName(@NotNull String name) {
35     myName = name;
36     return this;
37   }
38
39   @NotNull
40   public String call() throws VcsException {
41     GitCommandLine cmd = getCmd();
42     cmd.addParameters("config", myName);
43     ExecResult r = CommandUtil.runCommand(cmd);
44     CommandUtil.failIfNotEmptyStdErr(cmd, r);
45     return r.getStdout().trim();
46   }
47 }