Skip to content
quarry Artifact [fc4f66370c]
Login

Artifact [fc4f66370c]

Artifact fc4f66370c53d9dd28f9e291e0d0c9318627bebf02500afc352a7e4dec75e666:


package index

// AliasOf reports the branch a NAME actually resolves to, when that is
// a different name.
//
// A fossil branch can carry several propagating symbolic names at once,
// and a "rename" in practice adds a new one without cancelling the old.
// Both names then resolve to the same check-ins forever — measured
// across this forge's fleet, tcl, tk, tcllib and two test repositories
// all carry a live `trunk` beside `main`, with `trunk`'s tip being the
// newest check-in rather than one frozen at the rename.
//
// WHICH NAME WINS MATTERS FOR PROTECTION. A pushed check-in resolves to
// exactly ONE branch — its `branch` field, which is what the child
// matches protection globs against. So a rule naming a name that is not
// that one can never fire, however correct it looks on the page
// (d76e42b832f7).
//
// ok is false when the name is the branch's own name, and also when no
// check-in carries the name at all: a rule may legitimately name a
// branch that does not exist yet, and calling that an alias would
// refuse people protecting a release branch before the release.
func (ix *Index) AliasOf(name string) (string, bool, error) {
	if name == "" {
		return "", false, nil
	}
	tip, err := ix.branchTip(name)
	if err != nil || tip == "" {
		return "", false, err
	}
	of, err := ix.BranchOf([]string{tip})
	if err != nil {
		return "", false, err
	}
	real := of[tip]
	if real == "" || real == name {
		return "", false, nil
	}
	return real, true, nil
}