@@ -2,6 +2,7 @@ import gitLogParser from "git-log-parser";
22import getStream from "get-stream" ;
33import { execa } from "execa" ;
44import debugGit from "debug" ;
5+ import { merge } from "lodash-es" ;
56import { GIT_NOTE_REF } from "./definitions/constants.js" ;
67
78const debug = debugGit ( "semantic-release:git" ) ;
@@ -141,13 +142,9 @@ export async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
141142 */
142143export async function fetchNotes ( repositoryUrl , execaOptions ) {
143144 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 ) ;
149146 } 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/* ` ] , {
151148 ...execaOptions ,
152149 reject : false ,
153150 } ) ;
@@ -246,8 +243,8 @@ export async function push(repositoryUrl, execaOptions) {
246243 *
247244 * @throws {Error } if the push failed.
248245 */
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 ) ;
251248}
252249
253250/**
@@ -307,8 +304,26 @@ export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
307304 * @return {Object } the parsed JSON note if there is one, an empty object otherwise.
308305 */
309306export 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+
310316 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+ ) ;
312327 } catch ( error ) {
313328 if ( error . exitCode === 1 ) {
314329 return { } ;
@@ -327,5 +342,19 @@ export async function getNote(ref, execaOptions) {
327342 * @param {Object } [execaOpts] Options to pass to `execa`.
328343 */
329344export 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 ;
331360}
0 commit comments