diff --git a/core/cli/ci.el b/core/cli/ci.el index ba41316e6..b26fa68cc 100644 --- a/core/cli/ci.el +++ b/core/cli/ci.el @@ -22,20 +22,33 @@ ;;; -(defun doom-cli--ci-deploy-hooks (&optional noforce) - (let* ((default-directory doom-emacs-dir) - (dir (cdr (doom-call-process "git" "rev-parse" "--git-path" "hooks")))) - (make-directory dir 'parents) - (dolist (hook '("commit-msg" "pre-push")) - (let ((file (doom-path dir hook))) - (unless (and (file-exists-p file) noforce) - (with-temp-file file - (insert "#!/usr/bin/env sh\n" - (doom-path doom-emacs-dir "bin/doom") - " --nocolor ci hook-" hook - " \"$@\"")) - (set-file-modes file #o700) - (print! (success "Created %s") (relpath file))))))) +(defun doom-cli--ci-deploy-hooks (&optional force) + (let* ((repo-path (cdr (doom-call-process "git" "rev-parse" "--show-toplevel"))) + (submodule-p (string-empty-p (cdr (doom-call-process "git" "rev-parse" "show-superproject-working-tree")))) + (config-hooks-path (cdr (doom-call-process "git" "config" "core.hooksPath"))) + (hooks-path (cdr (doom-call-process "git" "rev-parse" "--git-path" "hooks")))) + (unless (string-empty-p config-hooks-path) + (or force + (y-or-n-p + (format (concat "Detected non-standard core.hookPath: %S\n\n" + "Install Doom's commit-msg and pre-push git hooks anyway?") + hooks-path)) + (user-error "Aborted"))) + (make-directory hooks-path 'parents) + (print! (start "Deploying git hooks in %S") (path hooks-path)) + (print-group! + (dolist (hook '("commit-msg" "pre-push")) + (let* ((hook (doom-path hooks-path hook)) + (overwrite-p (file-exists-p hook))) + (with-temp-file hook + (insert "#!/usr/bin/env sh\n" + (doom-path doom-emacs-dir "bin/doom") + " --nocolor ci hook-" (file-name-base hook) + " \"$@\"")) + (set-file-modes hook #o700) + (print! (success "%s %s") + (if overwrite-p "Overwrote" "Created") + (path hook))))))) ;; diff --git a/core/cli/install.el b/core/cli/install.el index 9049c54fe..2eff9a51d 100644 --- a/core/cli/install.el +++ b/core/cli/install.el @@ -24,7 +24,7 @@ name. e.g. DOOMDIR=~/.config/doom doom install" (print! (green "Installing Doom Emacs!\n")) - (let ((default-directory (doom-path "~"))) + (let ((default-directory doom-emacs-dir)) ;; Create `doom-private-dir' (if noconfig-p (print! (warn "Not copying private config template, as requested")) @@ -77,7 +77,11 @@ name. e.g. (if nohooks-p (print! (warn "Not deploying commit-msg and pre-push git hooks, as requested")) (print! "Deploying commit-msg and pre-push git hooks") - (doom-cli--ci-deploy-hooks)) + (print-group! + (condition-case e + (doom-cli--ci-deploy-hooks doom-auto-accept) + ('user-error + (print! (warn "%s") (error-message-string e)))))) (cond (nofonts-p) (IS-WINDOWS