1 package org.apache.maven.scm.provider.git.gitexe.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmBranch;
23 import org.apache.maven.scm.ScmRevision;
24 import org.apache.maven.scm.ScmTestCase;
25 import org.apache.maven.scm.ScmVersion;
26 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
27 import org.apache.maven.scm.repository.ScmRepository;
28 import org.codehaus.plexus.util.cli.Commandline;
29
30 import java.io.File;
31 import java.util.Calendar;
32 import java.util.Date;
33
34
35
36
37
38 public class GitChangeLogCommandTest
39 extends ScmTestCase
40 {
41 private File workingDirectory;
42
43 public void setUp() throws Exception
44 {
45 super.setUp();
46
47 workingDirectory = getTestFile( "target/git-update-command-test" );
48 }
49
50 public void testCommandLineNoDates()
51 throws Exception
52 {
53 testCommandLine( "scm:git:http://foo.com/git", null, (Date) null, (Date) null, 40,
54 "git whatchanged --date=iso --max-count=40 -- ." );
55 }
56
57 public void testCommandLineNoDatesLimitedCount()
58 throws Exception
59 {
60 testCommandLine( "scm:git:http://foo.com/git", null, (Date) null, (Date) null,
61 "git whatchanged --date=iso -- ." );
62 }
63
64 public void testCommandLineWithDates()
65 throws Exception
66 {
67 Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, GMT_TIME_ZONE );
68 Date endDate = getDate( 2007, Calendar.OCTOBER, 10, GMT_TIME_ZONE );
69
70 testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate,
71 "git whatchanged \"--since=2003-09-10 00:00:00 +0000\" \"--until=2007-10-10 00:00:00 +0000\" --date=iso -- ." );
72 }
73
74 public void testCommandLineStartDateOnly()
75 throws Exception
76 {
77 Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
78
79 testCommandLine( "scm:git:http://foo.com/git", null, startDate, null,
80 "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" --date=iso -- ." );
81 }
82
83 public void testCommandLineDateFormat()
84 throws Exception
85 {
86 Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
87 Date endDate = getDate( 2005, Calendar.NOVEMBER, 13, 23, 23, 23, GMT_TIME_ZONE );
88
89 testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate,
90 "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" --date=iso -- ." );
91 }
92
93 public void testCommandLineDateVersionRanges()
94 throws Exception
95 {
96 Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
97 Date endDate = getDate( 2005, Calendar.NOVEMBER, 13, 23, 23, 23, GMT_TIME_ZONE );
98
99 testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate, new ScmRevision( "1" ), new ScmRevision( "10" ),
100 "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" --date=iso 1..10 -- ." );
101 }
102
103 public void testCommandLineEndDateOnly()
104 throws Exception
105 {
106 Date endDate = getDate( 2003, Calendar.NOVEMBER, 10, GMT_TIME_ZONE );
107
108
109 testCommandLine( "scm:git:http://foo.com/git", null, null, endDate,
110 "git whatchanged \"--until=2003-11-10 00:00:00 +0000\" --date=iso -- ." );
111 }
112
113 public void testCommandLineWithBranchNoDates()
114 throws Exception
115 {
116 testCommandLine( "scm:git:http://foo.com/git", new ScmBranch( "my-test-branch" ), (Date) null, (Date) null,
117 "git whatchanged --date=iso my-test-branch -- ." );
118 }
119
120
121 public void testCommandLineWithStartVersion()
122 throws Exception
123 {
124 testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), null,
125 "git whatchanged --date=iso 1.. -- ." );
126 }
127
128 public void testCommandLineWithStartVersionAndEndVersion()
129 throws Exception
130 {
131 testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), new ScmRevision( "10" ),
132 "git whatchanged --date=iso 1..10 -- ." );
133 }
134
135 public void testCommandLineWithStartVersionAndEndVersionEquals()
136 throws Exception
137 {
138 testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), new ScmRevision( "1" ),
139 "git whatchanged --date=iso 1..1 -- ." );
140 }
141
142 public void testCommandLineWithStartVersionAndEndVersionAndBranch()
143 throws Exception
144 {
145 testCommandLine( "scm:git:http://foo.com/git", new ScmBranch( "my-test-branch" ), new ScmRevision( "1" ), new ScmRevision( "10" ),
146 "git whatchanged --date=iso 1..10 my-test-branch -- ." );
147 }
148
149
150
151
152
153 private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate, String commandLine )
154 throws Exception
155 {
156 testCommandLine( scmUrl, branch, startDate, endDate, null, commandLine );
157 }
158
159 private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate, Integer limit, String commandLine )
160 throws Exception
161 {
162 ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
163
164 GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
165
166 Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, startDate,
167 endDate, null, null, limit );
168
169 assertCommandLine( commandLine, workingDirectory, cl );
170 }
171
172 private void testCommandLine( String scmUrl, ScmBranch branch, ScmVersion startVersion, ScmVersion endVersion, String commandLine )
173 throws Exception
174 {
175 ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
176
177 GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
178
179 Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, null, null,
180 startVersion, endVersion );
181
182 assertCommandLine( commandLine, workingDirectory, cl );
183 }
184
185 private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate,
186 ScmVersion startVersion, ScmVersion endVersion, String commandLine )
187 throws Exception
188 {
189 ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
190
191 GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
192
193 Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, startDate, endDate,
194 startVersion, endVersion );
195
196 assertCommandLine( commandLine, workingDirectory, cl );
197 }
198 }