branch: elpa/magit
commit c3db9e139851cab0d46af08afefaf6cad1d5f146
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-{common-,}post-{commit,merge,rewrite}: New hooks
---
CHANGELOG | 5 ++++-
git-hooks/post-commit | 14 +++++++++++++-
git-hooks/post-merge | 14 +++++++++++++-
git-hooks/post-rewrite | 14 +++++++++++++-
lisp/magit-commit.el | 38 ++++++++++++++++++++++++++++++++++++++
lisp/magit-git.el | 9 ++++++++-
6 files changed, 89 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 19c96358058..02feea167ab 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,7 +13,10 @@
by ~magit-wip-mode~) and using the new ~magit-before-change-functions~
and ~magit-after-apply-functions~ hooks. 98ef107037..fa629ad5b5
-- Added experimental support for calling Lisp hooks from Git hooks.
+- Added experimental support for calling Lisp hooks from Git hooks,
+ and added a few such hooks: ~magit-common-git-post-commit-functions~,
+ ~magit-git-post-commit-functions~, ~magit-git-post-merge-functions~
+ and ~magit-git-post-rewrite-functions~.
- Replaced option ~magit-section-visibility-indicator~ (singluar) with
new option ~magit-section-visibility-indicators~ (plurarl) to better
diff --git a/git-hooks/post-commit b/git-hooks/post-commit
deleted file mode 120000
index 833950e79b1..00000000000
--- a/git-hooks/post-commit
+++ /dev/null
@@ -1 +0,0 @@
-fallthrough
\ No newline at end of file
diff --git a/git-hooks/post-commit b/git-hooks/post-commit
new file mode 100755
index 00000000000..79b9aa0e9b3
--- /dev/null
+++ b/git-hooks/post-commit
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+if [[ "$INSIDE_EMACS" == *magit ]]
+then
+ for arg in "$@"; do args+="\"$arg\""; done
+ $GIT_EDITOR --eval \
+ "(magit-run-git-hook '(common-post-commit post-commit) ${args[@]})"
+fi
+
+if [[ -x "$SHADOWED_GITHOOK_DIRECTORY" ]]
+then
+ "$SHADOWED_GITHOOK_DIRECTORY/$(basename $0)" "$@"
+fi
diff --git a/git-hooks/post-merge b/git-hooks/post-merge
deleted file mode 120000
index 833950e79b1..00000000000
--- a/git-hooks/post-merge
+++ /dev/null
@@ -1 +0,0 @@
-fallthrough
\ No newline at end of file
diff --git a/git-hooks/post-merge b/git-hooks/post-merge
new file mode 100755
index 00000000000..5716dee029b
--- /dev/null
+++ b/git-hooks/post-merge
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+if [[ "$INSIDE_EMACS" == *magit ]]
+then
+ for arg in "$@"; do args+="\"$arg\""; done
+ $GIT_EDITOR --eval \
+ "(magit-run-git-hook '(common-post-commit post-merge) ${args[@]})"
+fi
+
+if [[ -x "$SHADOWED_GITHOOK_DIRECTORY" ]]
+then
+ "$SHADOWED_GITHOOK_DIRECTORY/$(basename $0)" "$@"
+fi
diff --git a/git-hooks/post-rewrite b/git-hooks/post-rewrite
deleted file mode 120000
index 833950e79b1..00000000000
--- a/git-hooks/post-rewrite
+++ /dev/null
@@ -1 +0,0 @@
-fallthrough
\ No newline at end of file
diff --git a/git-hooks/post-rewrite b/git-hooks/post-rewrite
new file mode 100755
index 00000000000..128ddaaa2ed
--- /dev/null
+++ b/git-hooks/post-rewrite
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+if [[ "$INSIDE_EMACS" == *magit ]]
+then
+ for arg in "$@"; do args+="\"$arg\""; done
+ $GIT_EDITOR --eval \
+ "(magit-run-git-hook '(common-post-commit post-rewrite) ${args[@]})"
+fi
+
+if [[ -x "$SHADOWED_GITHOOK_DIRECTORY" ]]
+then
+ "$SHADOWED_GITHOOK_DIRECTORY/$(basename $0)" "$@"
+fi
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 44b5557f920..53e845d7047 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -99,6 +99,44 @@ Also see https://github.com/magit/magit/issues/4132."
:group 'magit-commands
:type 'boolean)
+(defvar magit-common-git-post-commit-functions nil
+ "Hook run by Git hooks `post-commit', `post-merge' and `post-rewrite'.
+
+This hook is run if `magit-overriding-githook-directory' is non-nil.
+The functions are called with the same arguments as the Git hook.
+
+This hook is still experimental.")
+
+(defvar magit-git-post-commit-functions nil
+ "Hook run by Git hook `post-commit'.
+
+This hook is run if `magit-overriding-githook-directory' is non-nil.
+The functions are called with the same arguments as the Git hook.
+
+See also `magit-common-git-post-commit-functions'.
+
+This hook is still experimental.")
+
+(defvar magit-git-post-merge-functions nil
+ "Hook run by Git hook `post-merge'.
+
+This hook is run if `magit-overriding-githook-directory' is non-nil.
+The functions are called with the same arguments as the Git hook.
+
+See also `magit-common-git-post-commit-functions'.
+
+This hook is still experimental.")
+
+(defvar magit-git-post-rewrite-functions nil
+ "Hook run by Git hook `post-rewrite'.
+
+This hook is run if `magit-overriding-githook-directory' is non-nil.
+The functions are called with the same arguments as the Git hook.
+
+See also `magit-common-git-post-commit-functions'.
+
+This hook is still experimental.")
+
;;; Popup
;;;###autoload(autoload 'magit-commit "magit-commit" nil t)
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index a2a5204bd4b..99fea61c41d 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -172,7 +172,14 @@ with Magit. To counteract Git's limited granularity,
Magit provides a
script for every Git hook, most of which only run the respective script
located in `$GIT_DIR/hooks', provided it exists and is executable.
-A few Git hooks additionally run Lisp hooks: TODO
+A few Git hooks additionally run Lisp hooks:
+
+- `post-commit' runs `magit-git-post-commit-functions'
+- `post-merge' runs `magit-git-post-merge-functions'
+- `post-rewrite' runs `magit-git-post-rewrite-functions'
+
+All of these hooks also run `magit-common-git-post-rewrite-functions'.
+For many uses this hook variable is more useful than the three above.
If you want to teach additional Git hooks to run Lisp hooks, you have to
copy Magit's hook script directory elsewhere, modify the hook scripts in