commands,config: permit (*configuration).HookDir() to error
In preparation for (*configuration).HookDir() to perform home-directory path expansion (e.g., expanding "~" to "/home/ttaylorr"), let's permit this function to return an error, should the path expansion fail. Path expansion can fail in any number of ways: either the current user does not have a home directory, the named user (e.g., "~user") does not have a home directory, or the named user does not exist. Instead of either (1) throwing the error from such a case away, or (2) rolling that error up into a panic(), let's allow ourselves a space to propagate it outwards. Since we do not yet support path expansion, let's always return "nil" for now, and update the call-sites to support non-nil return values, too.
This commit is contained in:
parent
35fe301c44
commit
97e11fd23b
@ -138,7 +138,11 @@ func downloadTransfer(p *lfs.WrappedPointer) (name, path, oid string, size int64
|
||||
|
||||
// Get user-readable manual install steps for hooks
|
||||
func getHookInstallSteps() string {
|
||||
hooks := lfs.LoadHooks(cfg.HookDir())
|
||||
hookDir, err := cfg.HookDir()
|
||||
if err != nil {
|
||||
ExitWithError(err)
|
||||
}
|
||||
hooks := lfs.LoadHooks(hookDir)
|
||||
steps := make([]string, 0, len(hooks))
|
||||
for _, h := range hooks {
|
||||
steps = append(steps, fmt.Sprintf(
|
||||
@ -150,7 +154,11 @@ func getHookInstallSteps() string {
|
||||
}
|
||||
|
||||
func installHooks(force bool) error {
|
||||
hooks := lfs.LoadHooks(cfg.HookDir())
|
||||
hookDir, err := cfg.HookDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hooks := lfs.LoadHooks(hookDir)
|
||||
for _, h := range hooks {
|
||||
if err := h.Install(force); err != nil {
|
||||
return err
|
||||
@ -166,7 +174,11 @@ func uninstallHooks() error {
|
||||
return errors.New("Not in a git repository")
|
||||
}
|
||||
|
||||
hooks := lfs.LoadHooks(cfg.HookDir())
|
||||
hookDir, err := cfg.HookDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hooks := lfs.LoadHooks(hookDir)
|
||||
for _, h := range hooks {
|
||||
if err := h.Uninstall(); err != nil {
|
||||
return err
|
||||
|
@ -268,14 +268,14 @@ func (c *Configuration) SetLockableFilesReadOnly() bool {
|
||||
return c.Os.Bool("GIT_LFS_SET_LOCKABLE_READONLY", true) && c.Git.Bool("lfs.setlockablereadonly", true)
|
||||
}
|
||||
|
||||
func (c *Configuration) HookDir() string {
|
||||
func (c *Configuration) HookDir() (string, error) {
|
||||
if git.IsGitVersionAtLeast("2.9.0") {
|
||||
hp, ok := c.Git.Get("core.hooksPath")
|
||||
if ok {
|
||||
return hp
|
||||
return hp, nil
|
||||
}
|
||||
}
|
||||
return filepath.Join(c.LocalGitDir(), "hooks")
|
||||
return filepath.Join(c.LocalGitDir(), "hooks"), nil
|
||||
}
|
||||
|
||||
func (c *Configuration) InRepo() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user