@@ -11,25 +11,7 @@ import { Given, When, Then } from '@cucumber/cucumber'
11
11
*/
12
12
13
13
Given ( 'another user pushed {int} commits to {string}' , async function ( this : BundleServerWorld , commitNum : number , branch : string ) {
14
- if ( this . remote && ! this . remote . isLocal ) {
15
- throw new Error ( "Remote is not initialized or does not allow pushes" )
16
- }
17
-
18
- const user = User . Another
19
- if ( ! this . repoMap . has ( user ) ) {
20
- this . cloneRepositoryFor ( user )
21
- utils . assertStatus ( 0 , this . getRepo ( user ) . cloneResult )
22
- }
23
- const clonedRepo = this . getRepo ( user )
24
-
25
- // TODO: figure out a better way to check whether the repo is empty
26
- if ( clonedRepo . runGit ( "show" ) . status != 0 ) {
27
- // Repo is empty, so make sure we're on the right branch
28
- clonedRepo . runGit ( "branch" , "-m" , branch )
29
- } else {
30
- clonedRepo . runGit ( "switch" , branch )
31
- clonedRepo . runGit ( "pull" , "origin" , branch )
32
- }
14
+ const clonedRepo = this . getRepoAtBranch ( User . Another , branch )
33
15
34
16
for ( let i = 0 ; i < commitNum ; i ++ ) {
35
17
utils . assertStatus ( 0 , clonedRepo . runShell ( `echo ${ randomBytes ( 16 ) . toString ( 'hex' ) } >README.md` ) )
@@ -39,6 +21,25 @@ Given('another user pushed {int} commits to {string}', async function(this: Bund
39
21
utils . assertStatus ( 0 , clonedRepo . runGit ( "push" , "origin" , branch ) )
40
22
} )
41
23
24
+ Given ( 'another developer removed {int} commits and added {int} commits to {string}' ,
25
+ async function ( this : BundleServerWorld , removeCommits : number , addCommits : number , branch : string ) {
26
+ const clonedRepo = this . getRepoAtBranch ( User . Another , branch )
27
+
28
+ // First, reset
29
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "reset" , "--hard" , `HEAD~${ removeCommits } ` ) )
30
+
31
+ // Then, add new commits
32
+ for ( let i = 0 ; i < addCommits ; i ++ ) {
33
+ utils . assertStatus ( 0 , clonedRepo . runShell ( `echo ${ randomBytes ( 16 ) . toString ( 'hex' ) } >README.md` ) )
34
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "add" , "README.md" ) )
35
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "commit" , "-m" , `test ${ i + 1 } ` ) )
36
+ }
37
+
38
+ // Finally, force push
39
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "push" , "-f" , "origin" , branch ) )
40
+ }
41
+ )
42
+
42
43
Given ( 'I cloned from the remote repo with a bundle URI' , async function ( this : BundleServerWorld ) {
43
44
const user = User . Me
44
45
this . cloneRepositoryFor ( user , this . bundleServer . bundleUri ( ) )
0 commit comments