vci

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: BSD-3-Clause Imports: 13 Imported by: 3

README

vci

Version Control Interface: provides a more complete VCS (e.g., git) interface, building on Masterminds/vcs.

vci adds the following methods on top of what is available in vcs.Repo:

  • Files -- files in the repository, and their FileStatus

  • Add, Move, Delete, CommitFile, RevertFile -- manipulate files in the repository.

  • Log, CommitDesc, Blame -- details on prior commits

The total interface is now sufficient for complete management of a VCS.

Current Status

Only git and svn are currently supported in vci -- other repositories supported in vcs include Mercurial (Hg) and Bazaar (Bzr) -- contributions from users of those VCS's are welcome.

Documentation

Overview

Package vci provides a version control interface for version control systems such as git, svn, etc. It extends vcs.Repo (https://github.com/Masterminds/vcs) with support for processing individual files within the repository.

Index

Constants

View Source
const (
	Version     = "v1.0.2"
	GitCommit   = "351b5ae"          // the commit JUST BEFORE the release
	VersionDate = "2023-09-02 22:28" // UTC
)

Variables

View Source
var (
	// ErrUnknownVCS is returned when VCS cannot be determined from the vcs Repo
	ErrUnknownVCS = errors.New("Unknown VCS")
)
View Source
var KiT_FileStatus = kit.Enums.AddEnum(FileStatusN, kit.NotBitFlag, nil)

Functions

func AllFiles

func AllFiles(path string) ([]string, error)

AllFiles returns a slice of all the files, recursively, within a given directory

func DetectRepo

func DetectRepo(path string) vcs.Type

DetectRepo attemps to detect the presence of a repository at the given directory path -- returns type of repository if found, else vcs.NoVCS. Very quickly just looks for signature file name: .git for git .svn for svn -- but note that this will find any subdir in svn repo

func FieldsThroughDelim

func FieldsThroughDelim(flds [][]byte, delim byte, idx int) (int, string)

FieldsThroughDelim gets the concatenated byte through to point where field ends with given delimiter, starting at given index

func RelPath

func RelPath(repo Repo, path string) string

RelPath return the path relative to the repository LocalPath()

Types

type Commit

type Commit struct {

	// revision number / hash code / unique id
	Rev string `desc:"revision number / hash code / unique id"`

	// date (author's time) when comitted
	Date string `desc:"date (author's time) when comitted"`

	// author's name
	Author string `desc:"author's name"`

	// author's email
	Email string `desc:"author's email"`

	// message / subject line for commit
	Message string `width:"100" desc:"message / subject line for commit"`
}

Commit is one VCS commit entry, as returned in a Log

type FileStatus

type FileStatus int32

FileStatus indicates the status of files in the repository

const (
	// Untracked means file is not under VCS control
	Untracked FileStatus = iota

	// Stored means file is stored under VCS control, and has not been modified in working copy
	Stored

	// Modified means file is under VCS control, and has been modified in working copy
	Modified

	// Added means file has just been added to VCS but is not yet committed
	Added

	// Deleted means file has been deleted from VCS
	Deleted

	// Conflicted means file is in conflict -- has not been merged
	Conflicted

	// Updated means file has been updated in the remote but not locally
	Updated

	FileStatusN
)

func (*FileStatus) FromString

func (i *FileStatus) FromString(s string) error

func (FileStatus) MarshalJSON

func (ev FileStatus) MarshalJSON() ([]byte, error)

func (FileStatus) String

func (i FileStatus) String() string

func (*FileStatus) UnmarshalJSON

func (ev *FileStatus) UnmarshalJSON(b []byte) error

type Files

type Files map[string]FileStatus

Files is a map used for storing files in a repository along with their status

func (*Files) Status

func (fl *Files) Status(repo Repo, fname string) FileStatus

Status returns the VCS file status associated with given filename, returning Untracked if not found and safe to empty map.

type GitRepo

type GitRepo struct {
	vcs.GitRepo
}

func (*GitRepo) Add

func (gr *GitRepo) Add(fname string) error

Add adds the file to the repo

func (*GitRepo) Blame

func (gr *GitRepo) Blame(fname string) ([]byte, error)

Blame returns an annotated report about the file, showing which revision last modified each line.

func (*GitRepo) CharToStat

func (gr *GitRepo) CharToStat(stat byte) FileStatus

func (*GitRepo) CommitDesc

func (gr *GitRepo) CommitDesc(rev string, diffs bool) ([]byte, error)

CommitDesc returns the full textual description of the given commit, if rev is empty, defaults to current HEAD, -1, -2 etc also work as universal ways of specifying prior revisions. Optionally includes diffs for the changes (otherwise just a list of files with modification status).

func (*GitRepo) CommitFile

func (gr *GitRepo) CommitFile(fname string, message string) error

CommitFile commits single file to repo staging

func (*GitRepo) Delete

func (gr *GitRepo) Delete(fname string) error

Delete removes the file from the repo -- uses "force" option to ensure deletion

func (*GitRepo) DeleteRemote

func (gr *GitRepo) DeleteRemote(fname string) error

Delete removes the file from the repo

func (*GitRepo) FileContents

func (gr *GitRepo) FileContents(fname string, rev string) ([]byte, error)

FileContents returns the contents of given file, as a []byte array at given revision specifier (if empty, defaults to current HEAD). -1, -2 etc also work as universal ways of specifying prior revisions.

func (*GitRepo) Files

func (gr *GitRepo) Files() (Files, error)

func (*GitRepo) Log

func (gr *GitRepo) Log(fname string, since string) (Log, error)

Log returns the log history of commits for given filename (or all files if empty). If since is non-empty, it should be a date-like expression that the VCS will understand, such as 1/1/2020, yesterday, last year, etc

func (*GitRepo) Move

func (gr *GitRepo) Move(oldpath, newpath string) error

Move moves updates the repo with the rename

func (*GitRepo) RevertFile

func (gr *GitRepo) RevertFile(fname string) error

RevertFile reverts a single file to last commit of master

func (*GitRepo) Status

func (gr *GitRepo) Status(fname string) (FileStatus, string)

Status returns status of given file -- returns Untracked on any error

type Log

type Log []*Commit

Log is the listing of commits

func (*Log) Add

func (lg *Log) Add(rev, date, author, email, message string) *Commit

type Repo

type Repo interface {
	// vcs.Repo includes those interface functions
	vcs.Repo

	// Files returns a map of the current files and their status.
	Files() (Files, error)

	// Status returns status of given file -- returns Untracked and error
	// message on any error. FileStatus is a summary status category,
	// and string return value is more detailed status information formatted
	// according to standard conventions of given VCS.
	Status(fname string) (FileStatus, string)

	// Add adds the file to the repo
	Add(fname string) error

	// Move moves the file using VCS command to keep it updated
	Move(oldpath, newpath string) error

	// Delete removes the file from the repo and working copy.
	// Uses "force" option to ensure deletion.
	Delete(fname string) error

	// DeleteRemote removes the file from the repo but keeps the local file itself
	DeleteRemote(fname string) error

	// CommitFile commits a single file
	CommitFile(fname string, message string) error

	// RevertFile reverts a single file to the version that it was last in VCS,
	// losing any local changes (destructive!)
	RevertFile(fname string) error

	// FileContents returns the contents of given file, as a []byte array
	// at given revision specifier (if empty, defaults to current HEAD).
	// -1, -2 etc also work as universal ways of specifying prior revisions.
	FileContents(fname string, rev string) ([]byte, error)

	// Log returns the log history of commits for given filename
	// (or all files if empty).  If since is non-empty, it should be
	// a date-like expression that the VCS will understand, such as
	// 1/1/2020, yesterday, last year, etc.  SVN only understands a
	// number as a maximum number of items to return.
	Log(fname string, since string) (Log, error)

	// CommitDesc returns the full textual description of the given commit,
	// if rev is empty, defaults to current HEAD, -1, -2 etc also work as universal
	// ways of specifying prior revisions.
	// Optionally includes diffs for the changes (otherwise just a list of files
	// with modification status).
	CommitDesc(rev string, diffs bool) ([]byte, error)

	// Blame returns an annotated report about the file, showing which revision last
	// modified each line.
	Blame(fname string) ([]byte, error)
}

Repo provides an interface extending vcs.Repo (https://github.com/Masterminds/vcs) with support for file status information and operations.

func NewRepo

func NewRepo(remote, local string) (Repo, error)

type SvnRepo

type SvnRepo struct {
	vcs.SvnRepo
}

func (*SvnRepo) Add

func (gr *SvnRepo) Add(fname string) error

Add adds the file to the repo

func (*SvnRepo) Blame

func (gr *SvnRepo) Blame(fname string) ([]byte, error)

Blame returns an annotated report about the file, showing which revision last modified each line.

func (*SvnRepo) CharToStat

func (gr *SvnRepo) CharToStat(stat byte) FileStatus

func (*SvnRepo) CommitDesc

func (gr *SvnRepo) CommitDesc(rev string, diffs bool) ([]byte, error)

CommitDesc returns the full textual description of the given commit, if rev is empty, defaults to current HEAD, -1, -2 etc also work as universal ways of specifying prior revisions. Optionally includes diffs for the changes (otherwise just a list of files with modification status).

func (*SvnRepo) CommitFile

func (gr *SvnRepo) CommitFile(fname string, message string) error

CommitFile commits single file to repo staging

func (*SvnRepo) Delete

func (gr *SvnRepo) Delete(fname string) error

Delete removes the file from the repo -- uses "force" option to ensure deletion

func (*SvnRepo) DeleteRemote

func (gr *SvnRepo) DeleteRemote(fname string) error

DeleteRemote removes the file from the repo, but keeps local copy

func (*SvnRepo) FileContents

func (gr *SvnRepo) FileContents(fname string, rev string) ([]byte, error)

FileContents returns the contents of given file, as a []byte array at given revision specifier (if empty, defaults to current HEAD). -1, -2 etc also work as universal ways of specifying prior revisions.

func (*SvnRepo) Files

func (gr *SvnRepo) Files() (Files, error)

func (*SvnRepo) Log

func (gr *SvnRepo) Log(fname string, since string) (Log, error)

Log returns the log history of commits for given filename (or all files if empty). If since is non-empty, it is the maximum number of entries to return (a number).

func (*SvnRepo) Move

func (gr *SvnRepo) Move(oldpath, newpath string) error

Move moves updates the repo with the rename

func (*SvnRepo) RevertFile

func (gr *SvnRepo) RevertFile(fname string) error

RevertFile reverts a single file to last commit of master

func (*SvnRepo) Status

func (gr *SvnRepo) Status(fname string) (FileStatus, string)

Status returns status of given file -- returns Untracked on any error

Jump to

Keyboard shortcuts

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