View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.git.command.branch;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.command.branch.BranchScmResult;
25  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
26  import org.apache.maven.scm.provider.git.GitScmTestUtils;
27  import org.apache.maven.scm.repository.ScmRepository;
28  import org.apache.maven.scm.tck.command.branch.BranchCommandTckTest;
29  import org.junit.Test;
30  
31  import static org.junit.Assert.assertFalse;
32  
33  /**
34   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
35   */
36  public abstract class GitBranchCommandTckTest extends BranchCommandTckTest {
37      /**
38       * {@inheritDoc}
39       */
40      public void initRepo() throws Exception {
41          GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
42      }
43  
44      @Override
45      protected CheckOutScmResult checkOut(File workingDirectory, ScmRepository repository) throws Exception {
46          try {
47              return super.checkOut(workingDirectory, repository);
48          } finally {
49              GitScmTestUtils.setDefaultGitConfig(workingDirectory);
50          }
51      }
52  
53      @Test
54      public void testPushBranchRejected() throws Exception {
55          String branch = getBranch();
56  
57          GitScmTestUtils.setupRejectAllCommitsPrePushHook(getWorkingCopy());
58          @SuppressWarnings("deprecation")
59          BranchScmResult branchResult = getScmManager()
60                  .getProviderByUrl(getScmUrl())
61                  .branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
62  
63          assertFalse("Branch should not have been pushed", branchResult.isSuccess());
64      }
65  }