UninstallHook removes the prepare-commit-msg hook if it exists. It retrieves the hooks directory path, checks if the hook file exists, and removes the hook file.
(ctx context.Context)
| 243 | // UninstallHook removes the prepare-commit-msg hook if it exists. |
| 244 | // It retrieves the hooks directory path, checks if the hook file exists, and removes the hook file. |
| 245 | func (c *Command) UninstallHook(ctx context.Context) error { |
| 246 | hookPath, err := c.hookPath(ctx).Output() |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | |
| 251 | target := path.Join(strings.TrimSpace(string(hookPath)), HookPrepareCommitMessageTemplate) |
| 252 | exists, err := file.IsFile(target) |
| 253 | if err != nil { |
| 254 | return err |
| 255 | } |
| 256 | if !exists { |
| 257 | return errors.New("hook file prepare-commit-msg is not exist") |
| 258 | } |
| 259 | return os.Remove(target) |
| 260 | } |
| 261 | |
| 262 | // New creates a new Command object with the provided options. |
| 263 | // It applies each option to the config object and initializes the Command object with the configurations. |