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  import org.codehaus.plexus.util.Os;
29  
30  import java.io.File;
31  
32  /**
33   * @author Bertrand Paquet
34   * @version $Id: GitExeCheckOutCommandNoBranchTest.java 1240126 2012-02-03 12:24:13Z olamy $
35   */
36  public class GitExeCheckOutCommandNoBranchTest
37      extends ScmTestCase
38  {
39      private File workingDirectory;
40  
41      private File repo;
42  
43      private ScmRepository scmRepository;
44  
45      public void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          workingDirectory = new File( "target/checkin-nobranch" );
51          FileUtils.deleteDirectory( workingDirectory );
52          repo = new File( "src/test/resources/repository_no_branch" );
53  
54          scmRepository = getScmManager().makeScmRepository( "scm:git:file:///" + repo.getAbsolutePath() );
55      }
56  
57      public void testCheckoutNoBranch()
58          throws Exception
59      {
60          if ( !ScmTestCase.isSystemCmd( "git" ) )
61          {
62              System.out.println( "skip test which git native executable in path" );
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              System.out.println( "skip test which git native executable in path" );
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  }