@@ -2,6 +2,7 @@ import gitLogParser from "git-log-parser";
2
2
import getStream from "get-stream" ;
3
3
import { execa } from "execa" ;
4
4
import debugGit from "debug" ;
5
+ import { merge } from "lodash-es" ;
5
6
import { GIT_NOTE_REF } from "./definitions/constants.js" ;
6
7
7
8
const debug = debugGit ( "semantic-release:git" ) ;
@@ -141,13 +142,9 @@ export async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
141
142
*/
142
143
export async function fetchNotes ( repositoryUrl , execaOptions ) {
143
144
try {
144
- await execa (
145
- "git" ,
146
- [ "fetch" , "--unshallow" , repositoryUrl , `+refs/notes/${ GIT_NOTE_REF } :refs/notes/${ GIT_NOTE_REF } ` ] ,
147
- execaOptions
148
- ) ;
145
+ await execa ( "git" , [ "fetch" , "--unshallow" , repositoryUrl , `+refs/notes/*:refs/notes/*` ] , execaOptions ) ;
149
146
} catch {
150
- await execa ( "git" , [ "fetch" , repositoryUrl , `+refs/notes/${ GIT_NOTE_REF } :refs/notes/${ GIT_NOTE_REF } ` ] , {
147
+ await execa ( "git" , [ "fetch" , repositoryUrl , `+refs/notes/* :refs/notes/* ` ] , {
151
148
...execaOptions ,
152
149
reject : false ,
153
150
} ) ;
@@ -246,8 +243,8 @@ export async function push(repositoryUrl, execaOptions) {
246
243
*
247
244
* @throws {Error } if the push failed.
248
245
*/
249
- export async function pushNotes ( repositoryUrl , execaOptions ) {
250
- await execa ( "git" , [ "push" , repositoryUrl , `refs/notes/${ GIT_NOTE_REF } ` ] , execaOptions ) ;
246
+ export async function pushNotes ( repositoryUrl , ref , execaOptions ) {
247
+ await execa ( "git" , [ "push" , repositoryUrl , `refs/notes/${ GIT_NOTE_REF } - ${ ref } ` ] , execaOptions ) ;
251
248
}
252
249
253
250
/**
@@ -307,8 +304,26 @@ export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
307
304
* @return {Object } the parsed JSON note if there is one, an empty object otherwise.
308
305
*/
309
306
export async function getNote ( ref , execaOptions ) {
307
+ const handleError = ( error ) => {
308
+ if ( error . exitCode === 1 ) {
309
+ return { stdout : "{}" } ;
310
+ }
311
+
312
+ debug ( error ) ;
313
+ throw error ;
314
+ } ;
315
+
310
316
try {
311
- return JSON . parse ( ( await execa ( "git" , [ "notes" , "--ref" , GIT_NOTE_REF , "show" , ref ] , execaOptions ) ) . stdout ) ;
317
+ return merge (
318
+ JSON . parse (
319
+ // Used for retro-compatibility
320
+ ( await execa ( "git" , [ "notes" , "--ref" , GIT_NOTE_REF , "show" , ref ] , execaOptions ) . catch ( handleError ) ) . stdout
321
+ ) ,
322
+ JSON . parse (
323
+ ( await execa ( "git" , [ "notes" , "--ref" , `${ GIT_NOTE_REF } -${ ref } ` , "show" , ref ] , execaOptions ) . catch ( handleError ) )
324
+ . stdout
325
+ )
326
+ ) ;
312
327
} catch ( error ) {
313
328
if ( error . exitCode === 1 ) {
314
329
return { } ;
@@ -327,5 +342,19 @@ export async function getNote(ref, execaOptions) {
327
342
* @param {Object } [execaOpts] Options to pass to `execa`.
328
343
*/
329
344
export async function addNote ( note , ref , execaOptions ) {
330
- await execa ( "git" , [ "notes" , "--ref" , GIT_NOTE_REF , "add" , "-f" , "-m" , JSON . stringify ( note ) , ref ] , execaOptions ) ;
345
+ await execa (
346
+ "git" ,
347
+ [ "notes" , "--ref" , `${ GIT_NOTE_REF } -${ ref } ` , "add" , "-f" , "-m" , JSON . stringify ( note ) , ref ] ,
348
+ execaOptions
349
+ ) ;
350
+ }
351
+
352
+ /**
353
+ * Get the reference of a tag
354
+ *
355
+ * @param {String } tag The tag name to get the reference of.
356
+ * @param {Object } [execaOpts] Options to pass to `execa`.
357
+ **/
358
+ export async function getTagRef ( tag , execaOptions ) {
359
+ return ( await execa ( "git" , [ "show-ref" , tag , "--hash" ] , execaOptions ) ) . stdout ;
331
360
}
0 commit comments