vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
| 1 | package main |
| 2 | |
| 3 | // Removing files attached to a release. Attaching uploads bytes and writes a |
| 4 | // pointer; this command only deletes pointers that already exist, so it needs no |
| 5 | // object-store transfer. The bytes stay in the shared store until nothing points |
| 6 | // at them and the garbage collector's grace period passes. |
| 7 | |
| 8 | import ( |
| 9 | "fmt" |
| 10 | "strings" |
| 11 | |
| 12 | "rodent.software/vole/client" |
| 13 | "rodent.software/vole/metadata" |
| 14 | ) |
| 15 | |
| 16 | // requireAnnotatedRelease refuses a tag that is not a release. Every file |
| 17 | // operation names the annotated tag whose releases/<tag>/ directory it edits; a |
| 18 | // lightweight tag has no such directory and no notes to attach anything to. |
| 19 | func requireAnnotatedRelease(c *client.Branch, tag string) error { |
| 20 | typ, err := c.Repo.Run(nil, "cat-file", "-t", "refs/tags/"+tag) |
| 21 | if err != nil { |
| 22 | return fmt.Errorf("no tag %s here; create and push the release first "+ |
| 23 | "(vole release create %s -F notes.md && git push --follow-tags)", tag, tag) |
| 24 | } |
| 25 | if strings.TrimSpace(string(typ)) != "tag" { |
| 26 | return fmt.Errorf("%s is a lightweight tag; a release needs an annotated tag with notes "+ |
| 27 | "(git tag -a %s -F notes.md)", tag, tag) |
| 28 | } |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | func cmdReleaseRemove(args []string) error { |
| 33 | f, err := parseFlags(args, releaseGroup.Flags...) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | if f.help { |
| 38 | fmt.Print(renderHelpText(releaseGroup)) |
| 39 | return nil |
| 40 | } |
| 41 | command := "vole release remove" |
| 42 | if err := f.checkAllowed(command); err != nil { |
| 43 | return err |
| 44 | } |
| 45 | if len(f.rest) < 2 { |
| 46 | return usageErr{msg: "usage: vole release remove <tag> <path>... [--remote <name>]"} |
| 47 | } |
| 48 | tag, paths := f.rest[0], f.rest[1:] |
| 49 | if strings.Contains(tag, "/") { |
| 50 | return fmt.Errorf("release tag %q must not contain '/'; an artifact path after it would be ambiguous", tag) |
| 51 | } |
| 52 | |
| 53 | c, err := client.NewBranch(f.one("remote"), metadata.Ref) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | if err := requireAnnotatedRelease(c, tag); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | message := fmt.Sprintf("release: %s remove %s", tag, strings.Join(paths, " ")) |
| 62 | write := func() error { |
| 63 | return metadata.RemoveReleasePointers(c.Repo, metadata.Ref, tag, paths, message, c.Author) |
| 64 | } |
| 65 | if err := write(); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | if err := c.CommitAndPush(false, write); err != nil { |
| 69 | return err |
| 70 | } |
| 71 | fmt.Printf("removed %d artifact(s) from %s on %s\n", len(paths), tag, metadata.Ref) |
| 72 | return nil |
| 73 | } |
| 74 |