Documentation
¶
Index ¶
- func Git(dir string, args ...string) *exec.Cmd
- type Repository
- func (r *Repository) Checkout(branch string) error
- func (r *Repository) Commit(message string) error
- func (r *Repository) GetCurrentBranch() (string, error)
- func (r *Repository) GetHeadSHA() (string, error)
- func (r *Repository) GetRemoteInfo() (owner, repo string, err error)
- func (r *Repository) GetRemoteURL() (string, error)
- func (r *Repository) GetWorkDir() (string, error)
- func (r *Repository) HasActivePreCommitHook() bool
- func (r *Repository) HasChanges() (bool, error)
- func (r *Repository) HasChangesIncludingUntracked() (bool, error)
- func (r *Repository) HasUnpushedCommits() (bool, error)
- func (r *Repository) Pull() error
- func (r *Repository) Push() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Git ¶
CIDX reads what git prints. It decides that a checkout failed only because another worktree holds the branch, that a push failed only because the remote ref was already gone, that a branch has no upstream yet -- all by matching git's own sentences, because git has no exit code that says which of those it was. Those sentences are translated. On a French machine git answers "la référence distante n'existe pas", every match misses, and CIDX reports a failure for the cases it was written to forgive (issue #364).
So git's output is made an interface CIDX controls instead of a setting the user happens to have. LC_ALL=C is the whole fix, and it is enough on its own: gettext ignores LANGUAGE when the locale is C, so there is no second variable to neutralize. It pins messages only in the sense that matters -- git writes commit subjects, paths and refs as the bytes it stored, not as text it re-encodes for the locale, so UTF-8 content still arrives intact.
The English that CIDX matches on is also the English that reaches the user in an error, which is the same language the rest of CIDX speaks.
TestEveryGitInvocationPinsTheLocale keeps this the only place that builds a git command: a call site that spells out exec.Command("git", ...) is born reading whatever git was configured to say, and the next parse written against it would be wrong on the same machines.
Types ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a Git repository
func OpenRepository ¶
func OpenRepository(path string) (*Repository, error)
OpenRepository opens a git repository at the given path
func (*Repository) Checkout ¶
func (r *Repository) Checkout(branch string) error
Checkout switches to a different branch using git binary
func (*Repository) Commit ¶
func (r *Repository) Commit(message string) error
Commit creates a commit with all changes using git binary This ensures pre-commit hooks are executed
func (*Repository) GetCurrentBranch ¶
func (r *Repository) GetCurrentBranch() (string, error)
GetCurrentBranch returns the name of the current branch
func (*Repository) GetHeadSHA ¶
func (r *Repository) GetHeadSHA() (string, error)
GetHeadSHA returns the commit SHA of the current HEAD
func (*Repository) GetRemoteInfo ¶
func (r *Repository) GetRemoteInfo() (owner, repo string, err error)
GetRemoteInfo extracts owner and repo name from remote origin URL
func (*Repository) GetRemoteURL ¶
func (r *Repository) GetRemoteURL() (string, error)
GetRemoteURL returns the URL of the origin remote
func (*Repository) GetWorkDir ¶
func (r *Repository) GetWorkDir() (string, error)
GetWorkDir returns the working directory path of the repository
func (*Repository) HasActivePreCommitHook ¶
func (r *Repository) HasActivePreCommitHook() bool
HasActivePreCommitHook reports whether `git commit` will run a pre-commit hook. It asks git for the effective hooks directory, so it answers for core.hooksPath (how this repository installs .githooks) as well as for the default .git/hooks — which ships only .sample files and so never matches.
Commit() shells out to the git binary precisely so hooks fire. cpw runs the code phase before committing (issue #307), and a hook that runs the same phase would run it twice: ~20 seconds paid for an answer already known. Nothing is inferred about what the hook checks — if a repository installed one, it is the repository's own gate and cpw stands aside for it.
func (*Repository) HasChanges ¶
func (r *Repository) HasChanges() (bool, error)
HasChanges checks if there are uncommitted changes (modified or staged files only, ignoring untracked)
This is the "would a release/tag be built from a dirty tree?" question: a stray scratch file next to the source must not block `pr create`, `tag create` or `release create`. Use HasChangesIncludingUntracked to ask "is there anything to commit?".
func (*Repository) HasChangesIncludingUntracked ¶
func (r *Repository) HasChangesIncludingUntracked() (bool, error)
HasChangesIncludingUntracked reports uncommitted changes the way Commit() sees them. Commit() runs `git add .`, so a brand-new file is something to commit; cpw asked HasChanges instead and answered "No changes to commit" while quietly leaving the user's new file behind (issue #180).
func (*Repository) HasUnpushedCommits ¶ added in v3.2.0
func (r *Repository) HasUnpushedCommits() (bool, error)
HasUnpushedCommits reports whether this branch holds commits the remote does not have.
`git rev-list --count @{u}..HEAD` answers it in one call, and the failure mode is the interesting half: a branch that was never pushed has no upstream to resolve, so git errors rather than answering zero. Reading that as "nothing to push" would strand exactly the branches most in need of a push — the brand new ones — so it counts as ahead (#416).
Like every other git decision here, it reads git's own sentences, which is why Git() pins LC_ALL=C (#364).
func (*Repository) Pull ¶
func (r *Repository) Pull() error
Pull pulls latest changes from remote using git binary
func (*Repository) Push ¶
func (r *Repository) Push() error
Push pushes commits to remote using git binary. Automatically sets upstream for new branches.