lfs/attribute, hook: rename Path to Section, nuke HookType type

This commit is contained in:
Taylor Blau 2015-09-02 14:57:09 -04:00
parent 3b9b0f2b7f
commit e56d63064c
3 changed files with 16 additions and 41 deletions

@ -15,29 +15,29 @@ var (
// Attribute wraps the structure and some operations of Git's conception of an
// "attribute", as defined here: http://git-scm.com/docs/gitattributes.
type Attribute struct {
// The Path of an Attribute refers to the path at which all properties
// are relative to. For example, for a Path with the value "core", Git
// will produce something like:
// The Section of an Attribute refers to the location at which all
// properties are relative to. For example, for a Section with the value
// "core", Git will produce something like:
//
// [core]
// autocrlf = true
// ...
Path string
Section string
// The Properties of an Attribute refer to all of the keys and values
// that define that Attribute.
Properties map[string]string
}
// Install instructs Git to set all keys and values relative to the root Path of
// this Attribute. For any particular key/value pair, if a matching key is
// already set, it will be overridden if it is either a) empty, or b) the
// Install instructs Git to set all keys and values relative to the root
// location of this Attribute. For any particular key/value pair, if a matching
// key is already set, it will be overridden if it is either a) empty, or b) the
// `force` argument is passed as true. If an attribute is already set to a
// different value than what is given, and force is false, an error will be
// returned immediately, and the rest of the attributes will not be set.
func (a *Attribute) Install(force bool) error {
for k, v := range a.Properties {
key := a.normalizePath(k)
key := a.normalizeKey(k)
if err := a.set(key, v, force); err != nil {
return err
}
@ -46,10 +46,10 @@ func (a *Attribute) Install(force bool) error {
return nil
}
// normalizePath makes an absolute path out of a partial relative one. For a
// relative path of "foo", and a root Path of "bar", "bar.foo" will be returned.
func (a *Attribute) normalizePath(relative string) string {
return strings.Join([]string{a.Path, relative}, ".")
// normalizeKey makes an absolute path out of a partial relative one. For a
// relative path of "foo", and a root Section of "bar", "bar.foo" will be returned.
func (a *Attribute) normalizeKey(relative string) string {
return strings.Join([]string{a.Section, relative}, ".")
}
// set attempts to set a single key/value pair portion of this Attribute. If a
@ -73,7 +73,7 @@ func (a *Attribute) set(key, value string, force bool) error {
// Uninstall removes all properties in the path of this property.
func (a *Attribute) Uninstall() {
git.Config.UnsetGlobalSection(a.Path)
git.Config.UnsetGlobalSection(a.Section)
}
// shouldReset determines whether or not a value is resettable given its current

@ -9,36 +9,11 @@ import (
"strings"
)
// A HookType represents a type of Git hook as defined in
// http://git-scm.com/docs/githooks.
type HookType string
const (
ApplyPatchMessageHook HookType = "applypatch-msg"
PreApplyPatchHook = "pre-applypatch"
PostApplyPatchHook = "post-applypatch"
PreCommitHook = "pre-commit"
PrepareCommitMessageHook = "prepare-commit-msg"
CommitMessageHook = "commit-msg"
PostCommitHook = "post-commit"
PreRebaseHook = "pre-rebase"
PostCheckoutHook = "post-checkout"
PostMergeHook = "post-merge"
PrePushHook = "pre-push"
PreReceiveHook = "pre-receive"
UpdateHook = "update"
PostReceiveHook = "post-receive"
PostUpdateHook = "post-update"
PushToCheckoutHook = "push-to-checkout"
PostRewriteHook = "post-rewrite"
RebaseHook = "rebase"
)
// A Hook represents a githook as described in http://git-scm.com/docs/githooks.
// Hooks have a type, which is the type of hook that they are, and a body, which
// represents the thing they will execute when invoked by Git.
type Hook struct {
Type HookType
Type string
Contents string
Upgradeables []string
}

@ -3,7 +3,7 @@ package lfs
var (
// prePushHook invokes `git lfs push` at the pre-push phase.
prePushHook = &Hook{
Type: PrePushHook,
Type: "pre-push",
Contents: "#!/bin/sh\ncommand -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\\n\"; exit 2; }\ngit lfs pre-push \"$@\"",
Upgradeables: []string{
"#!/bin/sh\ngit lfs push --stdin $*",
@ -19,7 +19,7 @@ var (
}
filters = &Attribute{
Path: "filter.lfs",
Section: "filter.lfs",
Properties: map[string]string{
"clean": "git-lfs clean %f",
"smudge": "git-lfs smudge %f",