mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-22 14:38:51 +00:00
git: push --tags support.
This commit is contained in:
44
git.go
44
git.go
@@ -455,11 +455,17 @@ aside from those, there is also:
|
|||||||
{
|
{
|
||||||
Name: "push",
|
Name: "push",
|
||||||
Usage: "push git changes",
|
Usage: "push git changes",
|
||||||
Flags: append(defaultKeyFlags, &cli.BoolFlag{
|
Flags: append(defaultKeyFlags,
|
||||||
|
&cli.BoolFlag{
|
||||||
Name: "force",
|
Name: "force",
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
Usage: "force push to git remotes",
|
Usage: "force push to git remotes",
|
||||||
}),
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "tags",
|
||||||
|
Usage: "push all refs under refs/tags",
|
||||||
|
},
|
||||||
|
),
|
||||||
Action: func(ctx context.Context, c *cli.Command) error {
|
Action: func(ctx context.Context, c *cli.Command) error {
|
||||||
// setup signer
|
// setup signer
|
||||||
kr, _, err := gatherKeyerFromArguments(ctx, c)
|
kr, _, err := gatherKeyerFromArguments(ctx, c)
|
||||||
@@ -526,6 +532,37 @@ aside from those, there is also:
|
|||||||
log("- setting HEAD to branch %s\n", color.CyanString(remoteBranch))
|
log("- setting HEAD to branch %s\n", color.CyanString(remoteBranch))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add all refs/tags
|
||||||
|
output, err := exec.Command("git", "show-ref", "--tags").Output()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get local tags: %s", err)
|
||||||
|
} else {
|
||||||
|
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts := strings.Fields(line)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
commitHash := parts[0]
|
||||||
|
ref := parts[1]
|
||||||
|
|
||||||
|
tagName := strings.TrimPrefix(ref, "refs/tags/")
|
||||||
|
|
||||||
|
if !c.Bool("force") {
|
||||||
|
// if --force is not passed then we can't overwrite tags
|
||||||
|
if existingHash, exists := state.Tags[tagName]; exists && existingHash != commitHash {
|
||||||
|
return fmt.Errorf("tag %s that is already published pointing to %s, call with --force to overwrite", tagName, existingHash)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.Tags[tagName] = commitHash
|
||||||
|
log("- setting tag %s to commit %s\n", color.CyanString(tagName), color.CyanString(commitHash))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create and sign the new state event
|
// create and sign the new state event
|
||||||
newStateEvent := state.ToEvent()
|
newStateEvent := state.ToEvent()
|
||||||
err = kr.SignEvent(ctx, &newStateEvent)
|
err = kr.SignEvent(ctx, &newStateEvent)
|
||||||
@@ -553,6 +590,9 @@ aside from those, there is also:
|
|||||||
if c.Bool("force") {
|
if c.Bool("force") {
|
||||||
pushArgs = append(pushArgs, "--force")
|
pushArgs = append(pushArgs, "--force")
|
||||||
}
|
}
|
||||||
|
if c.Bool("tags") {
|
||||||
|
pushArgs = append(pushArgs, "--tags")
|
||||||
|
}
|
||||||
pushCmd := exec.Command("git", pushArgs...)
|
pushCmd := exec.Command("git", pushArgs...)
|
||||||
pushCmd.Stderr = os.Stderr
|
pushCmd.Stderr = os.Stderr
|
||||||
pushCmd.Stdout = os.Stdout
|
pushCmd.Stdout = os.Stdout
|
||||||
|
|||||||
Reference in New Issue
Block a user