Skip to content

Commit 3225157

Browse files
WeslleyNasRochaJounQin
authored andcommitted
fix: add early return for empty tag list in pushTags function
1 parent 1a929f3 commit 3225157

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/git-utils.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@ export const push = async (
2727
}
2828

2929
export const pushTags = async () => {
30+
// Get the commit hash
31+
const { stdout: commitHash } = await execWithOutput("git", [
32+
"rev-parse",
33+
"HEAD",
34+
]);
3035
// Get the tags that contain the commit
31-
const { stdout: tags } = await execWithOutput('git', [
32-
'--no-pager',
33-
'tag',
34-
`HEAD`,
35-
])
36+
const { stdout: tags } = await execWithOutput("git", [
37+
"--no-pager",
38+
"tag",
39+
"--contains",
40+
commitHash,
41+
]);
3642
// Separate the tags into a list
37-
const tagList = tags.split('\n')
38-
if (tagList.length > 0) {
39-
// Push the tags individually to the remote
40-
for (const tag of tagList) {
41-
await exec('git', ['push', 'origin', tag])
42-
}
43+
const tagList = tags.split("\n");
44+
// Push the tags individually to the remote
45+
for (const tag of tagList) {
46+
await exec("git", ["push", "origin", tag]);
4347
}
44-
}
48+
};
49+
4550

4651
export const switchToMaybeExistingBranch = async (branch: string) => {
4752
const { stderr } = await execWithOutput('git', ['checkout', branch], {

0 commit comments

Comments
 (0)