Skip to content

bug: tag handling and exit in pre-push-update-version.js #193

@Ishita-190

Description

@Ishita-190

Description
I noticed some issues that may cause problems in the hook: pre-push-update-version.js

await run('git', ['tag', '-d', latestTag]);

Deletes and recreates the latest tag, which changes tag identity and can break signed or annotated tags.

resp = await run('git', ['rev-list', '--tags', '--max-count=1']);

Selects the newest tagged commit instead of the highest semver tag, could cause version mismatches

process.exit(e.exit);

may be undefined, so the script could exit successfully even when it fails

Proposed Changes:

1. Use semver-aware tag selection

Replace:

resp = await run('git', ['rev-list', '--tags', '--max-count=1']);

with :

resp = await run('git', ['tag', '--list', 'v*.*.*', '--sort=-v:refname']);

const latestTag = resp.stdout
  .split('\n')
  .map(tag => tag.trim())
  .find(Boolean);

if (!latestTag) {
  process.stderr.write(
    '\x1b[0;31mNo version tags found matching v*.*.*. Aborting push.\x1b[0m\n'
  );
  process.exit(1);
}

2. Remove destructive tag rewrite

Remove:

await run('git', ['tag', '-d', latestTag]);
await run('git', ['tag', latestTag]);

Update the retry message to:

process.stderr.write(
  '\x1b[0;32mPush again with: \x1b[0mgit push ' +
    remoteName +
    ' ' +
    currentBranch +
    '\n'
);

3. Safe exit handling

Replace:

process.exit(e.exit);

with:

console.error(e && e.message ? e.message : 'pre-push-update-version failed');
const exitCode = Number.isInteger(e && e.exit) ? e.exit : 1;
process.exit(exitCode);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions