View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.checkin;
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.add.AddScmResult;
26  import org.apache.maven.scm.command.checkin.CheckInScmResult;
27  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
28  import org.apache.maven.scm.repository.ScmRepository;
29  import org.codehaus.plexus.util.FileUtils;
30  
31  import java.io.File;
32  
33  /**
34   * @author Bertrand Paquet
35   */
36  public class GitCheckInCommandNoBranchTest
37      extends ScmTestCase
38  {
39  
40      private File workingDirectory;
41  
42      public void setUp()
43          throws Exception
44      {
45          super.setUp();
46  
47          workingDirectory = new File( "target/checkin-nobranch" );
48      }
49  
50      public void testCheckinNoBranch()
51          throws Exception
52      {
53          if ( !ScmTestCase.isSystemCmd( "git" ) )
54          {
55              System.out.println( "skip test which git native executable in path" );
56              return;
57          }
58          File repo_orig = new File( "src/test/resources/repository_no_branch" );
59          File repo = getTestFile( "target/git_copy" );
60          FileUtils.deleteDirectory( repo );
61          FileUtils.copyDirectoryStructure( repo_orig, repo );
62  
63          ScmRepository scmRepository = getScmManager().makeScmRepository( "scm:git:file:///" + repo.getAbsolutePath() );
64          CheckOutScmResult checkOutScmResult = checkoutRepo( scmRepository );
65          assertEquals( 0, checkOutScmResult.getCheckedOutFiles().size() );
66  
67          File f = new File( workingDirectory.getAbsolutePath() + File.separator + "pom.xml" );
68          FileUtils.fileWrite( f.getAbsolutePath(), "toto" );
69  
70          ScmFileSet scmFileSet = new ScmFileSet( workingDirectory, new File( "pom.xml" ) );
71          AddScmResult addResult = getScmManager().add( scmRepository, scmFileSet );
72          assertResultIsSuccess( addResult );
73  
74          CheckInScmResult checkInScmResult = getScmManager().checkIn( scmRepository, scmFileSet, "commit" );
75          assertResultIsSuccess( checkInScmResult );
76          assertEquals( 1, checkInScmResult.getCheckedInFiles().size() );
77          assertEquals( "pom.xml", checkInScmResult.getCheckedInFiles().get( 0 ).getPath() );
78  
79          checkOutScmResult = checkoutRepo( scmRepository );
80          assertResultIsSuccess( checkOutScmResult );
81          assertEquals( 1, checkOutScmResult.getCheckedOutFiles().size() );
82          assertEquals( "pom.xml", checkOutScmResult.getCheckedOutFiles().get( 0 ).getPath() );
83      }
84  
85      protected CheckOutScmResult checkoutRepo( ScmRepository scmRepository )
86          throws Exception
87      {
88          FileUtils.deleteDirectory( workingDirectory );
89  
90          CheckOutScmResult result =
91              getScmManager().checkOut( scmRepository, new ScmFileSet( workingDirectory ), (ScmVersion) null );
92  
93          assertResultIsSuccess( result );
94          return result;
95      }
96  }