forget: Add --unsafe-allow-remove-all option

To prevent accidentally wiping all snapshots from a repository, that
option can only be used if either a snapshot filter or a keep policy is
specified.

Essentially, the option allows `forget --tag something
--unsafe-allow-remove-all` calls to remove all snapshots with a specific
tag.
This commit is contained in:
Michael Eischer
2024-04-15 22:02:14 +02:00
parent 5b7952e426
commit 57f9739573
3 changed files with 17 additions and 1792 deletions

View File

@@ -94,7 +94,11 @@ func (e ExpirePolicy) String() (s string) {
s += fmt.Sprintf("all snapshots within %s of the newest", e.Within)
}
s = "keep " + s
if s == "" {
s = "remove"
} else {
s = "keep " + s
}
return s
}
@@ -186,16 +190,6 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason
// sort newest snapshots first
sort.Stable(list)
if p.Empty() {
for _, sn := range list {
reasons = append(reasons, KeepReason{
Snapshot: sn,
Matches: []string{"policy is empty"},
})
}
return list, remove, reasons
}
if len(list) == 0 {
return list, nil, nil
}

File diff suppressed because it is too large Load Diff