summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-03-13 17:51:41 +0100
committerLudovic Courtès <ludo@gnu.org>2024-05-01 17:26:19 +0200
commit8d1d98a3aa3448b9d983e4bd64243a938b96e8ab (patch)
treeb9f677f4b88872700c87c45e3c453bf46dce83dd /guix
parent1a5041a502ee26c04d264983232b2aaa6a5e27d8 (diff)
git authenticate: Install pre-push and post-checkout hooks.
* guix/scripts/git/authenticate.scm (install-hooks): New procedure. (guix-git-authenticate): Use it. * doc/guix.texi (Invoking guix git authenticate): Document it. Change-Id: I4464a33193186e85b476a12740e54412bd58429c
Diffstat (limited to 'guix')
-rw-r--r--guix/scripts/git/authenticate.scm49
1 files changed, 48 insertions, 1 deletions
diff --git a/guix/scripts/git/authenticate.scm b/guix/scripts/git/authenticate.scm
index 0797cba0b6..e3ecb67c89 100644
--- a/guix/scripts/git/authenticate.scm
+++ b/guix/scripts/git/authenticate.scm
@@ -148,6 +148,52 @@ in repository configuration file~%")))
(warning (G_ "could not record introduction and keyring configuration\
(Guile-Git too old?)~%"))))
+(define (install-hooks repository)
+ "Attempt to install in REPOSITORY hooks that invoke 'guix git authenticate'.
+Bail out if one of these already exists."
+ ;; Guile-Git < 0.7.0 lacks 'repository-common-directory'.
+ (if (module-defined? (resolve-interface '(git))
+ 'repository-common-directory)
+ (let ()
+ (define directory
+ (repository-common-directory repository))
+
+ (define pre-push-hook
+ (in-vicinity directory "hooks/pre-push"))
+
+ (define post-merge-hook
+ (in-vicinity directory "hooks/post-merge"))
+
+ (if (or (file-exists? pre-push-hook)
+ (file-exists? post-merge-hook))
+ (begin
+ (warning (G_ "not overriding pre-existing hooks '~a' and '~a'~%")
+ pre-push-hook post-merge-hook)
+ (display-hint (G_ "Consider running @command{guix git authenticate}
+from your pre-push and post-merge hooks so your repository is automatically
+authenticated before you push and when you pull updates.")))
+ (begin
+ (call-with-output-file pre-push-hook
+ (lambda (port)
+ (format port "#!/bin/sh
+# Installed by 'guix git authenticate'.
+set -e
+while read local_ref local_oid remote_ref remote_oid
+do
+ guix git authenticate --end=\"$local_oid\"
+done\n")
+ (chmod port #o755)))
+ (call-with-output-file post-merge-hook
+ (lambda (port)
+ (format port "#!/bin/sh
+# Installed by 'guix git authenticate'.
+exec guix git authenticate\n")
+ (chmod port #o755)))
+ (info (G_ "installed hooks '~a' and '~a'~%")
+ pre-push-hook post-merge-hook))))
+ (warning (G_ "cannot determine where to install hooks\
+ (Guile-Git too old?)~%"))))
+
(define (show-stats stats)
"Display STATS, an alist containing commit signing stats as returned by
'authenticate-repository'."
@@ -271,7 +317,8 @@ expected COMMIT and SIGNER~%")))
(unless (configured? repository)
(record-configuration repository
#:commit commit #:signer signer
- #:keyring-reference keyring))
+ #:keyring-reference keyring)
+ (install-hooks repository))
(when (and show-stats? (not (null? stats)))
(show-stats stats))