1 | |
package org.apache.maven.scm.provider.hg.command.checkin; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import org.apache.maven.scm.ScmException; |
27 | |
import org.apache.maven.scm.ScmFile; |
28 | |
import org.apache.maven.scm.ScmFileSet; |
29 | |
import org.apache.maven.scm.ScmFileStatus; |
30 | |
import org.apache.maven.scm.ScmResult; |
31 | |
import org.apache.maven.scm.ScmVersion; |
32 | |
import org.apache.maven.scm.command.checkin.AbstractCheckInCommand; |
33 | |
import org.apache.maven.scm.command.checkin.CheckInScmResult; |
34 | |
import org.apache.maven.scm.command.status.StatusScmResult; |
35 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
36 | |
import org.apache.maven.scm.provider.hg.HgUtils; |
37 | |
import org.apache.maven.scm.provider.hg.command.HgCommandConstants; |
38 | |
import org.apache.maven.scm.provider.hg.command.HgConsumer; |
39 | |
import org.apache.maven.scm.provider.hg.command.status.HgStatusCommand; |
40 | |
import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository; |
41 | |
import org.codehaus.plexus.util.StringUtils; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class HgCheckInCommand |
49 | |
extends AbstractCheckInCommand |
50 | |
{ |
51 | |
|
52 | |
|
53 | |
|
54 | |
protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message, |
55 | |
ScmVersion tag ) |
56 | |
throws ScmException |
57 | |
{ |
58 | 0 | if ( tag != null && !StringUtils.isEmpty( tag.getName() ) ) |
59 | |
{ |
60 | 0 | throw new ScmException( "This provider can't handle tags for this operation" ); |
61 | |
} |
62 | |
|
63 | |
|
64 | 0 | File workingDir = fileSet.getBasedir(); |
65 | 0 | String branchName = HgUtils.getCurrentBranchName( getLogger(), workingDir ); |
66 | 0 | boolean differentOutgoingBranch = repo.isPushChanges() ? HgUtils.differentOutgoingBranchFound( getLogger(), workingDir, branchName ) : false; |
67 | |
|
68 | |
|
69 | 0 | List<ScmFile> commitedFiles = new ArrayList<ScmFile>(); |
70 | 0 | List<File> files = fileSet.getFileList(); |
71 | 0 | if ( files.isEmpty() ) |
72 | |
{ |
73 | 0 | HgStatusCommand statusCmd = new HgStatusCommand(); |
74 | 0 | statusCmd.setLogger( getLogger() ); |
75 | 0 | StatusScmResult status = statusCmd.executeStatusCommand( repo, fileSet ); |
76 | 0 | List<ScmFile> statusFiles = status.getChangedFiles(); |
77 | 0 | for ( ScmFile file : statusFiles ) |
78 | |
{ |
79 | 0 | if ( file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || |
80 | |
file.getStatus() == ScmFileStatus.MODIFIED ) |
81 | |
{ |
82 | 0 | commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) ); |
83 | |
} |
84 | |
} |
85 | |
|
86 | 0 | } |
87 | |
else |
88 | |
{ |
89 | 0 | for ( File file : files ) |
90 | |
{ |
91 | 0 | commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) ); |
92 | |
} |
93 | |
} |
94 | |
|
95 | |
|
96 | 0 | String[] commitCmd = new String[]{ HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, message }; |
97 | 0 | commitCmd = HgUtils.expandCommandLine( commitCmd, fileSet ); |
98 | 0 | ScmResult result = |
99 | |
HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), commitCmd ); |
100 | |
|
101 | |
|
102 | 0 | HgScmProviderRepository repository = (HgScmProviderRepository) repo; |
103 | |
|
104 | 0 | if ( repo.isPushChanges() ) |
105 | |
{ |
106 | |
|
107 | 0 | if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) ) |
108 | |
{ |
109 | 0 | String[] pushCmd = new String[]{ HgCommandConstants.PUSH_CMD, |
110 | |
differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null, |
111 | |
repository.getURI() }; |
112 | |
|
113 | 0 | result = HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), pushCmd ); |
114 | |
} |
115 | |
|
116 | 0 | return new CheckInScmResult( commitedFiles, result ); |
117 | |
} |
118 | |
|
119 | 0 | return new CheckInScmResult( commitedFiles, result ); |
120 | |
} |
121 | |
|
122 | |
|
123 | |
} |