3
3
package com .googlesource .gerrit .plugins .qtcodereview ;
4
4
5
5
import static com .google .common .truth .Truth .assertThat ;
6
+ import static com .google .gerrit .extensions .client .ListChangesOption .CURRENT_REVISION ;
6
7
import static com .google .gerrit .server .group .SystemGroupBackend .REGISTERED_USERS ;
7
8
9
+ import com .google .common .collect .ImmutableList ;
8
10
import com .google .gerrit .acceptance .PushOneCommit ;
9
11
import com .google .gerrit .acceptance .TestPlugin ;
10
12
import com .google .gerrit .acceptance .UseSsh ;
11
13
import com .google .gerrit .common .data .Permission ;
14
+ import com .google .gerrit .extensions .api .changes .Changes ;
15
+ import com .google .gerrit .extensions .client .ChangeStatus ;
16
+ import com .google .gerrit .extensions .common .ChangeInfo ;
17
+ import com .google .gerrit .reviewdb .client .Branch ;
12
18
import com .google .gerrit .reviewdb .client .Change ;
13
19
import com .google .gerrit .reviewdb .client .ChangeMessage ;
14
20
import java .io .StringBufferInputStream ;
@@ -29,7 +35,10 @@ public class QtCommandBuildApproveIT extends QtCodeReviewIT {
29
35
30
36
@ Before
31
37
public void SetDefaultPermissions () throws Exception {
38
+ createBranch (new Branch .NameKey (project , "feature" ));
39
+
32
40
grant (project , "refs/heads/master" , Permission .QT_STAGE , false , REGISTERED_USERS );
41
+ grant (project , "refs/heads/feature" , Permission .QT_STAGE , false , REGISTERED_USERS );
33
42
grant (project , "refs/staging/*" , Permission .PUSH , false , adminGroupUuid ());
34
43
grant (project , "refs/builds/*" , Permission .CREATE , false , adminGroupUuid ());
35
44
}
@@ -79,6 +88,48 @@ public void singleChange_New_Staged_Integrating_Fail() throws Exception {
79
88
RevCommit updatedHead = qtFailBuild ("master" , "test-build-200" , c , initialHead );
80
89
}
81
90
91
+ @ Test
92
+ public void cherryPicked_Stays_Intact_After_Merge_And_Build () throws Exception {
93
+ // make a change on feature branch
94
+ final PushOneCommit .Result f1 = pushCommit ("feature" , "f1-commitmsg" , "f1-file" , "f1-content" );
95
+ approve (f1 .getChangeId ());
96
+ gApi .changes ().id (f1 .getCommit ().getName ()).current ().submit ();
97
+
98
+ // cherry pick it to the master branch (now there are two changes with same change-id)
99
+ final ChangeInfo cp = cherryPick (f1 , "master" );
100
+
101
+ // make another change on feature branch
102
+ final PushOneCommit .Result f2 = pushCommit ("feature" , "f2-commitmsg" , "f2-file" , "f2-content" );
103
+ approve (f2 .getChangeId ());
104
+ QtStage (f2 );
105
+ QtNewBuild ("feature" , "feature-build-000" );
106
+ QtApproveBuild ("feature" , "feature-build-000" );
107
+
108
+ // make a change on master branch
109
+ final PushOneCommit .Result m1 = pushCommit ("master" , "m1-commitmsg" , "m1-file" , "m1-content" );
110
+ approve (m1 .getChangeId ());
111
+ QtStage (m1 );
112
+ QtNewBuild ("master" , "master-build-000" );
113
+ QtApproveBuild ("master" , "master-build-000" );
114
+
115
+ // merge feature branch into master
116
+ final PushOneCommit mm = pushFactory .create (admin .newIdent (), testRepo );
117
+ mm .setParents (ImmutableList .of (f2 .getCommit (), m1 .getCommit ()));
118
+ final PushOneCommit .Result m = mm .to ("refs/for/master" );
119
+ m .assertOkStatus ();
120
+ approve (m .getChangeId ());
121
+ QtStage (m );
122
+ QtNewBuild ("master" , "merge-build-000" );
123
+ QtApproveBuild ("master" , "merge-build-000" );
124
+
125
+ final Changes changes = gApi .changes ();
126
+ assertThat (changes .id (project .get (), "feature" , f1 .getChangeId ()).get (CURRENT_REVISION ).status ).isEqualTo (ChangeStatus .MERGED );
127
+ assertThat (changes .id (project .get (), "feature" , f2 .getChangeId ()).get (CURRENT_REVISION ).status ).isEqualTo (ChangeStatus .MERGED );
128
+ assertThat (changes .id (project .get (), "master" , m1 .getChangeId ()).get (CURRENT_REVISION ).status ).isEqualTo (ChangeStatus .MERGED );
129
+ assertThat (changes .id (project .get (), "master" , m .getChangeId ()).get (CURRENT_REVISION ).status ).isEqualTo (ChangeStatus .MERGED );
130
+ assertThat (changes .id (project .get (), "master" , cp .changeId ).get (CURRENT_REVISION ).status ).isEqualTo (ChangeStatus .NEW );
131
+ }
132
+
82
133
@ Test
83
134
public void multiChange_New_Staged_Integrating_Failed () throws Exception {
84
135
// Push 3 independent commits
0 commit comments