upgrade

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package upgrade implements template upgrading: taking a directory containing a rendered template and updating it with the latest version of the template.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.8.0

type Action string

An Action is an action to take for a given output file. This may involve conflicts between upgraded template output files and files that were locally customized by the user.

For the mergeActions named e.g. "editDelete", the first thing is what the user did locally ("edit") and the second thing is want the template wants to do ("delete").

const (
	// Just write the contents of the file from the new template.
	WriteNew Action = "writeNew"

	// Just DeleteAction the preexisting file in the template output directory.
	// We can't just call this "delete" because that's a Go builtin.
	DeleteAction Action = "delete"

	// Take no action, the current contents of the output directory are correct.
	Noop Action = "noop"

	// The user manually created a file, and the template also wants to create
	// that file. This is a conflict requiring the user to resolve.
	AddAddConflict Action = "addAddConflict"

	// The template originally outputted a file, which the user then edited. Now
	// the template wants to change the file, but we don't want to clobber the
	// user's edits, so we have to ask them to manually resolve the differences.
	EditEditConflict Action = "editEditConflict"

	// The template originally outputted a file, which the user then edited. Now
	// the template wants to delete the file, but we don't want to clobber the
	// user's edits, so we have to ask them to manually resolve the differences.
	EditDeleteConflict Action = "editDeleteConflict"

	// The template originally outputted a file, which the user then deleted.
	// Now the template wants to change the file. The user might want the newly
	// changed file despite having deleted the previous version of the file, so
	// we'll require them to manually resolve.
	DeleteEditConflict Action = "deleteEditConflict"
)

func (Action) IsConflict added in v0.8.0

func (a Action) IsConflict() bool

type ActionTaken added in v0.8.0

type ActionTaken struct {
	Action Action

	// Explanation is a human-readable reason why the given Action was chosen
	// for this path.
	Explanation string

	// This is the Path to the single file that this ActionTaken is about. It is
	// always set.
	//
	// This is a relative path, starting from the directory where the template
	// is installed.
	Path string

	// OursPath is only set for certain types of merge conflict. This is the
	// path that the local file was renamed to that needs manual merge
	// resolution.
	//
	// This is a relative path, starting from the directory where the template
	// is installed.
	OursPath string

	// IncomingTemplatePath is only set for certain types of merge conflict.
	// This is the path to the incoming template file that needs merge
	// resolution.
	//
	// This is a relative path, starting from the directory where the template
	// is installed.
	IncomingTemplatePath string
}

ActionTaken represents an output of the merge operation. Every file that's part of the template output will have an ActionTaken that explains what the merge algorithm decided to do for this file (e.g. Noop, EditEditConflict, or other), and why.

If there was a merge conflict, then files may have been renamed. See OursPath and IncomingTemplatePath.

type Params

type Params struct {
	Clock clock.Clock

	// CWD is the value of os.Getwd(), or in testing, a temp directory.
	CWD string

	// The value of --debug-scratch-contents.
	DebugScratchContents bool

	// The value of --debug-step-diffs.
	DebugStepDiffs bool

	// FS abstracts filesystem operations for error injection testing.
	FS common.FS

	// The value of --git-protocol.
	GitProtocol string

	// The value of --input-file.
	InputFiles []string

	// The value of --input.
	Inputs map[string]string

	// The value of --keep-temp-dirs.
	KeepTempDirs bool

	// The path to the manifest file where the template was previously installed
	// to that will now be upgraded. This is also overwritten with the new
	// manifest after a successful upgrade.
	ManifestPath string // Must be an absolute path.

	// The value of --prompt.
	Prompt   bool
	Prompter input.Prompter

	// Relative paths where patch reversal has already happened. This is a flag
	// supplied by the user. This will be set if there were merge conflicts
	// during patch reversal that were manually resolved by the user.
	// TODO(upgrade): add this as a CLI flag and plumb it through to here.
	ReversalAlreadyDone []string

	// The value of --skip-input-validation.
	SkipInputValidation bool

	// Used in tests to do prompting for inputs even though the input is not a
	// TTY.
	SkipPromptTTYCheck bool

	// The output stream used to print prompts when Prompt==true.
	Stdout io.Writer

	// Empty string, except in tests. Will be used as the parent of temp dirs.
	TempDirBase string
}

Params contains all the arguments to Upgrade().

type Result added in v0.8.0

type Result struct {
	// If no upgrade was done because this installation of the template is
	// already on the latest version, then this will be true and all other
	// fields in this struct will have zero values.
	Type ResultType

	// The paths to files where abc tried to apply the reversal
	// patches from the manifest to included-from-destination files, and the
	// patches could not be applied cleanly. Manual resolution is needed.
	//
	// This field should only be used when Type==PatchReversalConflict.
	ReversalConflicts []*ReversalConflict

	// Conflicts is the set of files that require manual intervention by the
	// user to resolve a merge conflict. For example, there may be a file that
	// was edited by the user and that edit conflicts with changes to that same
	// file by the upgraded version of the template.
	//
	// This field should only be used when Type==MergeConflict.
	Conflicts []ActionTaken

	// NonConflicts is the set of template output files that do NOT require any
	// action by the user. Callers are free to ignore this.
	//
	// This is mutually exclusive with "Conflicts". Each file is in at most one
	// of the two lists.
	//
	// This field should only be used when Type is Success or MergeConflict.
	NonConflicts []ActionTaken
}

Result is returned from Upgrade if there's no error. It may indicate that there were merge conflicts requiring manual resolution.

func Upgrade

func Upgrade(ctx context.Context, p *Params) (_ *Result, rErr error)

Upgrade takes a directory containing previously rendered template output and updates it using the newest version of the template, which is pointed to by the manifest file.

Returns true if the upgrade occurred, or false if the upgrade was skipped because we're already on the latest version of the template.

type ResultType added in v0.8.0

type ResultType string
const (
	// This is the value of Result.Type when the upgrade was vacuously
	// successful because the template is already on the latest version.
	AlreadyUpToDate ResultType = "already_up_to_date"

	// This is the value of Result.Type when there was an upgrade and it was
	// successful, and no user intervention is needed.
	Success ResultType = "success"

	// This is the value of Result.Type when abc tried to apply the reversal
	// patches from the manifest to included-from-destination files, and the
	// patches could not be applied cleanly. User intervention is needed, and
	// the ReversalConflicts field should be used.
	PatchReversalConflict ResultType = "patch_reversal_conflict"

	// The new version of the template conflicted with local modifications and
	// manual resolution is required. The Conflicts field should be used.
	MergeConflict ResultType = "merge_conflict"
)

type ReversalConflict added in v0.8.0

type ReversalConflict struct {
	// The relative path to the file that needs manual resolution.
	Path string
}

ReversalConflict happens when abc tried to apply the reversal patches from the manifest to included-from-destination files, and the patches could not be applied cleanly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL