From e56d63064ce4c7e2d8899b2ccc5fc8185a3df663 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Wed, 2 Sep 2015 14:57:09 -0400 Subject: [PATCH] lfs/attribute, hook: rename Path to Section, nuke HookType type --- lfs/attribute.go | 26 +++++++++++++------------- lfs/{hooks.go => hook.go} | 27 +-------------------------- lfs/setup.go | 4 ++-- 3 files changed, 16 insertions(+), 41 deletions(-) rename lfs/{hooks.go => hook.go} (73%) diff --git a/lfs/attribute.go b/lfs/attribute.go index 6d9922fa..a4bcd511 100644 --- a/lfs/attribute.go +++ b/lfs/attribute.go @@ -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 diff --git a/lfs/hooks.go b/lfs/hook.go similarity index 73% rename from lfs/hooks.go rename to lfs/hook.go index e82e0ffd..1da3ec07 100644 --- a/lfs/hooks.go +++ b/lfs/hook.go @@ -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 } diff --git a/lfs/setup.go b/lfs/setup.go index 3ac5f6fb..925f64c2 100644 --- a/lfs/setup.go +++ b/lfs/setup.go @@ -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",