@@ -72,3 +72,61 @@ test('get edit commit message while skipping first commit', async () => {
7272 const actual = await read ( { from : 'HEAD~2' , cwd, gitLogArgs : '--skip 1' } ) ;
7373 expect ( actual ) . toEqual ( expected ) ;
7474} ) ;
75+
76+ test ( 'should only read the last commit' , async ( ) => {
77+ const cwd : string = await git . bootstrap ( ) ;
78+
79+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit Z' ] , { cwd} ) ;
80+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit Y' ] , { cwd} ) ;
81+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit X' ] , { cwd} ) ;
82+
83+ const result = await read ( { cwd, last : true } ) ;
84+
85+ expect ( result ) . toEqual ( [ 'commit X' ] ) ;
86+ } ) ;
87+
88+ test ( 'should read commits from the last annotated tag' , async ( ) => {
89+ const cwd : string = await git . bootstrap ( ) ;
90+
91+ await execa (
92+ 'git' ,
93+ [ 'commit' , '--allow-empty' , '-m' , 'chore: release v1.0.0' ] ,
94+ { cwd}
95+ ) ;
96+ await execa ( 'git' , [ 'tag' , 'v1.0.0' , '--annotate' , '-m' , 'v1.0.0' ] , { cwd} ) ;
97+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit 1' ] , { cwd} ) ;
98+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit 2' ] , { cwd} ) ;
99+
100+ const result = await read ( { cwd, fromLastTag : true } ) ;
101+
102+ expect ( result ) . toEqual ( [ 'commit 2\n\n' , 'commit 1\n\n' ] ) ;
103+ } ) ;
104+
105+ test ( 'should read commits from the last lightweight tag' , async ( ) => {
106+ const cwd : string = await git . bootstrap ( ) ;
107+
108+ await execa (
109+ 'git' ,
110+ [ 'commit' , '--allow-empty' , '-m' , 'chore: release v9.9.9-alpha.1' ] ,
111+ { cwd}
112+ ) ;
113+ await execa ( 'git' , [ 'tag' , 'v9.9.9-alpha.1' ] , { cwd} ) ;
114+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit A' ] , { cwd} ) ;
115+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit B' ] , { cwd} ) ;
116+
117+ const result = await read ( { cwd, fromLastTag : true } ) ;
118+
119+ expect ( result ) . toEqual ( [ 'commit B\n\n' , 'commit A\n\n' ] ) ;
120+ } ) ;
121+
122+ test ( 'should not read any commits when there are no tags' , async ( ) => {
123+ const cwd : string = await git . bootstrap ( ) ;
124+
125+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit 7' ] , { cwd} ) ;
126+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit 8' ] , { cwd} ) ;
127+ await execa ( 'git' , [ 'commit' , '--allow-empty' , '-m' , 'commit 9' ] , { cwd} ) ;
128+
129+ const result = await read ( { cwd, fromLastTag : true } ) ;
130+
131+ expect ( result ) . toHaveLength ( 0 ) ;
132+ } ) ;
0 commit comments