View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.checkout;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmFileSet;
23  import org.apache.maven.scm.ScmTestCase;
24  import org.apache.maven.scm.ScmVersion;
25  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
26  import org.apache.maven.scm.repository.ScmRepository;
27  import org.codehaus.plexus.util.FileUtils;
28  
29  import java.io.File;
30  
31  /**
32   * @author Bertrand Paquet
33   *
34   */
35  public class GitExeCheckOutCommandNoBranchTest
36      extends ScmTestCase
37  {
38      private File workingDirectory;
39  
40      private File repo;
41  
42      private ScmRepository scmRepository;
43  
44      public void setUp()
45          throws Exception
46      {
47          super.setUp();
48  
49          workingDirectory = new File( "target/checkin-nobranch" );
50          FileUtils.deleteDirectory( workingDirectory );
51          repo = new File( "src/test/resources/repository_no_branch" );
52  
53          scmRepository = getScmManager().makeScmRepository( "scm:git:" +
54                              repo.toPath().toAbsolutePath().toUri().toASCIIString() );
55      }
56  
57      public void testCheckoutNoBranch()
58          throws Exception
59      {
60          if ( !ScmTestCase.isSystemCmd( "git" ) )
61          {
62              ScmTestCase.printSystemCmdUnavail( "git", getName() );
63              return;
64          }
65          CheckOutScmResult result = checkoutRepo();
66          assertEquals( 0, result.getCheckedOutFiles().size() );
67      }
68  
69      public void testDoubleCheckoutNoBranch()
70          throws Exception
71      {
72          if ( !ScmTestCase.isSystemCmd( "git" ) )
73          {
74              ScmTestCase.printSystemCmdUnavail( "git", getName() );
75              return;
76          }
77          CheckOutScmResult result = checkoutRepo();
78          assertEquals( 0, result.getCheckedOutFiles().size() );
79          CheckOutScmResult result2 = checkoutRepo();
80          assertEquals( 0, result2.getCheckedOutFiles().size() );
81      }
82  
83      protected CheckOutScmResult checkoutRepo()
84          throws Exception
85      {
86          CheckOutScmResult result =
87              getScmManager().checkOut( scmRepository, new ScmFileSet( workingDirectory ), (ScmVersion) null );
88  
89          assertResultIsSuccess( result );
90          return result;
91      }
92  }