lfs/attribute, hook: rename Path to Section, nuke HookType type
This commit is contained in:
parent
3b9b0f2b7f
commit
e56d63064c
@ -15,29 +15,29 @@ var (
|
|||||||
// Attribute wraps the structure and some operations of Git's conception of an
|
// Attribute wraps the structure and some operations of Git's conception of an
|
||||||
// "attribute", as defined here: http://git-scm.com/docs/gitattributes.
|
// "attribute", as defined here: http://git-scm.com/docs/gitattributes.
|
||||||
type Attribute struct {
|
type Attribute struct {
|
||||||
// The Path of an Attribute refers to the path at which all properties
|
// The Section of an Attribute refers to the location at which all
|
||||||
// are relative to. For example, for a Path with the value "core", Git
|
// properties are relative to. For example, for a Section with the value
|
||||||
// will produce something like:
|
// "core", Git will produce something like:
|
||||||
//
|
//
|
||||||
// [core]
|
// [core]
|
||||||
// autocrlf = true
|
// autocrlf = true
|
||||||
// ...
|
// ...
|
||||||
Path string
|
Section string
|
||||||
|
|
||||||
// The Properties of an Attribute refer to all of the keys and values
|
// The Properties of an Attribute refer to all of the keys and values
|
||||||
// that define that Attribute.
|
// that define that Attribute.
|
||||||
Properties map[string]string
|
Properties map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install instructs Git to set all keys and values relative to the root Path of
|
// Install instructs Git to set all keys and values relative to the root
|
||||||
// this Attribute. For any particular key/value pair, if a matching key is
|
// location of this Attribute. For any particular key/value pair, if a matching
|
||||||
// already set, it will be overridden if it is either a) empty, or b) the
|
// 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
|
// `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
|
// 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.
|
// returned immediately, and the rest of the attributes will not be set.
|
||||||
func (a *Attribute) Install(force bool) error {
|
func (a *Attribute) Install(force bool) error {
|
||||||
for k, v := range a.Properties {
|
for k, v := range a.Properties {
|
||||||
key := a.normalizePath(k)
|
key := a.normalizeKey(k)
|
||||||
if err := a.set(key, v, force); err != nil {
|
if err := a.set(key, v, force); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ func (a *Attribute) Install(force bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizePath makes an absolute path out of a partial relative one. For a
|
// normalizeKey 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.
|
// relative path of "foo", and a root Section of "bar", "bar.foo" will be returned.
|
||||||
func (a *Attribute) normalizePath(relative string) string {
|
func (a *Attribute) normalizeKey(relative string) string {
|
||||||
return strings.Join([]string{a.Path, relative}, ".")
|
return strings.Join([]string{a.Section, relative}, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
// set attempts to set a single key/value pair portion of this Attribute. If a
|
// 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.
|
// Uninstall removes all properties in the path of this property.
|
||||||
func (a *Attribute) Uninstall() {
|
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
|
// shouldReset determines whether or not a value is resettable given its current
|
||||||
|
@ -9,36 +9,11 @@ import (
|
|||||||
"strings"
|
"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.
|
// 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
|
// 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.
|
// represents the thing they will execute when invoked by Git.
|
||||||
type Hook struct {
|
type Hook struct {
|
||||||
Type HookType
|
Type string
|
||||||
Contents string
|
Contents string
|
||||||
Upgradeables []string
|
Upgradeables []string
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ package lfs
|
|||||||
var (
|
var (
|
||||||
// prePushHook invokes `git lfs push` at the pre-push phase.
|
// prePushHook invokes `git lfs push` at the pre-push phase.
|
||||||
prePushHook = &Hook{
|
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 \"$@\"",
|
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{
|
Upgradeables: []string{
|
||||||
"#!/bin/sh\ngit lfs push --stdin $*",
|
"#!/bin/sh\ngit lfs push --stdin $*",
|
||||||
@ -19,7 +19,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
filters = &Attribute{
|
filters = &Attribute{
|
||||||
Path: "filter.lfs",
|
Section: "filter.lfs",
|
||||||
Properties: map[string]string{
|
Properties: map[string]string{
|
||||||
"clean": "git-lfs clean %f",
|
"clean": "git-lfs clean %f",
|
||||||
"smudge": "git-lfs smudge %f",
|
"smudge": "git-lfs smudge %f",
|
||||||
|
Loading…
Reference in New Issue
Block a user