43
43
44
44
import static org .junit .Assert .*;
45
45
import org .opensolaris .opengrok .util .Executor ;
46
+ import org .opensolaris .opengrok .util .IOUtils ;
46
47
import org .opensolaris .opengrok .util .TestRepository ;
47
48
48
49
/**
@@ -78,24 +79,15 @@ private void setUpTestRepository() throws IOException {
78
79
repository = new TestRepository ();
79
80
repository .create (getClass ().getResourceAsStream ("repositories.zip" ));
80
81
81
- // Fix the CVS/Root so that it points to the temporary directory
82
- // rather than the workspace directory.
83
- // Normally this would be bad idea since every subdirectory includes
84
- // CVS/Root file however in this case there is just one such file
85
- // as the repository is flat in terms of directory structure.
86
- // This is done so that 'cvs update' does not change the "upstream"
87
- // cvsroot directory entries.
88
- // The alternative would be to checkout cvsrepo from cvsroot.
89
- // XXX no proper path separators + newline char below
90
- File root = new File (repository .getSourceRoot (), "cvs_test/cvsrepo/CVS/Root" );
91
- if (root .isFile ()) {
92
- FileChannel outChan = new FileOutputStream (root , true ).getChannel ();
93
- outChan .truncate (0 );
94
- outChan .close ();
95
- }
96
- FileWriter fw = new FileWriter (root );
97
- fw .write (repository .getSourceRoot () + "/cvs_test/cvsroot\n " );
98
- fw .close ();
82
+ // Checkout cvsrepo anew in order to get the CVS/Root files point to
83
+ // the temporary directory rather than the OpenGrok workspace directory
84
+ // it was created from. This is necessary since 'cvs update' changes
85
+ // the CVS parent directory after branch has been created.
86
+ File root = new File (repository .getSourceRoot (), "cvs_test" );
87
+ File cvsrepodir = new File (root , "cvsrepo" );
88
+ IOUtils .removeRecursive (cvsrepodir .toPath ());
89
+ File cvsroot = new File (root , "cvsroot" );
90
+ runCvsCommand (root , "-d" , cvsroot .getAbsolutePath (), "checkout" , "cvsrepo" );
99
91
}
100
92
101
93
@ After
@@ -114,23 +106,21 @@ public void setUp() {
114
106
}
115
107
116
108
/**
117
- * Run the 'cvs' command.
109
+ * Run the 'cvs' command with some arguments .
118
110
*
119
111
* @param reposRoot directory of the repository root
120
- * @param command command to run
121
- * @param arg argument to use for the command
112
+ * @param args arguments to use for the command
122
113
*/
123
- private static void runCvsCommand (File reposRoot , String command , String ... args ) {
114
+ private static void runCvsCommand (File reposRoot , String ... args ) {
124
115
List <String > cmdargs = new ArrayList <>();
125
116
cmdargs .add (CVSRepository .CMD_FALLBACK );
126
- cmdargs .add (command );
127
117
for (String arg : args ) {
128
118
cmdargs .add (arg );
129
119
}
130
120
Executor exec = new Executor (cmdargs , reposRoot );
131
121
int exitCode = exec .exec ();
132
122
if (exitCode != 0 ) {
133
- fail ("cvs " + command + " failed."
123
+ fail ("cvs command ' " + cmdargs . toString () + "' failed."
134
124
+ "\n exit code: " + exitCode
135
125
+ "\n stdout:\n " + exec .getOutputString ()
136
126
+ "\n stderr:\n " + exec .getErrorString ());
@@ -152,7 +142,8 @@ public void testGetBranchNoBranch() throws Exception {
152
142
}
153
143
154
144
/**
155
- * Get the CVS repository, create new branch and verify getBranch() returns it.
145
+ * Get the CVS repository, create new branch and verify getBranch() returns it
146
+ * and check newly added commits annotate with branch revision numbers.
156
147
* @throws Exception
157
148
*/
158
149
@ Test
@@ -171,6 +162,20 @@ public void testGetBranchNewBranch() throws Exception {
171
162
= (CVSRepository ) RepositoryFactory .getRepository (root );
172
163
173
164
assertEquals ("mybranch" , cvsrepo .getBranch ());
165
+
166
+ // Change the content and commit.
167
+ File mainC = new File (root , "main.c" );
168
+ FileChannel outChan = new FileOutputStream (mainC , true ).getChannel ();
169
+ outChan .truncate (0 );
170
+ outChan .close ();
171
+ FileWriter fw = new FileWriter (mainC );
172
+ fw .write ("#include <foo.h>\n " );
173
+ fw .close ();
174
+ runCvsCommand (root , "commit" , "-m" , "change on a branch" , "main.c" );
175
+
176
+ // Check that annotation for the changed line has branch revision.
177
+ Annotation annotation = cvsrepo .annotate (mainC , null );
178
+ assertEquals ("1.2.2.1" , annotation .getRevision (1 ));
174
179
}
175
180
176
181
/**
0 commit comments