mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-25 05:48:07 -05:00
etc: committer: Amend previous commit if a copyright line was added.
Previously, the script would raise an error if a copyright line was added to a file in gnu/packages/. With this change, it will amend the previous commit whenever a copyright line is added, and add the copyright line to the commit. * etc/committer.scm.in (add-copyright-line): New procedure. (main): Check if a copyright line was added and call ‘add-copyright-line’ if necessary. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
dbf758ac5e
commit
3d15a19874
1 changed files with 22 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
|
||||||
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
|
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
|
||||||
|
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -288,6 +289,15 @@ (define (changelog-has-location? changelog)
|
||||||
(break-string-with-newlines message/f 72)
|
(break-string-with-newlines message/f 72)
|
||||||
(break-string-with-newlines changelog/f 72))))
|
(break-string-with-newlines changelog/f 72))))
|
||||||
|
|
||||||
|
(define (add-copyright-line line)
|
||||||
|
"Add the copyright line on LINE to the previous commit."
|
||||||
|
(let ((author (match:substring
|
||||||
|
(string-match "^\\+;;; Copyright ©[^[:alpha:]]+(.*)$" line)
|
||||||
|
1)))
|
||||||
|
(format
|
||||||
|
(current-output-port) "Amend and add copyright line for ~a~%" author)
|
||||||
|
(system* "git" "commit" "--amend" "--no-edit")))
|
||||||
|
|
||||||
(define (group-hunks-by-sexp hunks)
|
(define (group-hunks-by-sexp hunks)
|
||||||
"Return a list of pairs associating all hunks with the S-expression they are
|
"Return a list of pairs associating all hunks with the S-expression they are
|
||||||
modifying."
|
modifying."
|
||||||
|
@ -370,15 +380,23 @@ (define* (change-commit-message* file-name old new #:rest rest)
|
||||||
(error "Cannot apply")))
|
(error "Cannot apply")))
|
||||||
(usleep %delay))
|
(usleep %delay))
|
||||||
hunks)
|
hunks)
|
||||||
(change-commit-message* (hunk-file-name (first hunks))
|
(define copyright-line
|
||||||
old new)
|
(any (lambda (line) (and=> (string-prefix? "+;;; Copyright ©" line)
|
||||||
(let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
|
(const line)))
|
||||||
|
(hunk-diff-lines (first hunks))))
|
||||||
|
(cond
|
||||||
|
(copyright-line
|
||||||
|
(add-copyright-line copyright-line))
|
||||||
|
(else
|
||||||
|
(let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
|
||||||
|
(change-commit-message* (hunk-file-name (first hunks))
|
||||||
|
old new)
|
||||||
(change-commit-message* (hunk-file-name (first hunks))
|
(change-commit-message* (hunk-file-name (first hunks))
|
||||||
old new
|
old new
|
||||||
port)
|
port)
|
||||||
(usleep %delay)
|
(usleep %delay)
|
||||||
(unless (eqv? 0 (status:exit-val (close-pipe port)))
|
(unless (eqv? 0 (status:exit-val (close-pipe port)))
|
||||||
(error "Cannot commit")))))
|
(error "Cannot commit")))))))
|
||||||
;; XXX: we recompute the hunks here because previous
|
;; XXX: we recompute the hunks here because previous
|
||||||
;; insertions lead to offsets.
|
;; insertions lead to offsets.
|
||||||
(new+old+hunks (diff-info)))))))
|
(new+old+hunks (diff-info)))))))
|
||||||
|
|
Loading…
Reference in a new issue