From patchwork Sat Feb 1 11:43:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: 45mg <45mg.writes@gmail.com> X-Patchwork-Id: 38142 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 23E9727BBEA; Sat, 1 Feb 2025 11:46:42 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6BEB327BBE2 for ; Sat, 1 Feb 2025 11:46:41 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1teBws-0007Kz-8F; Sat, 01 Feb 2025 06:46:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1teBwq-0007Kg-NI for guix-patches@gnu.org; Sat, 01 Feb 2025 06:46:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1teBwq-0005dr-C2; Sat, 01 Feb 2025 06:46:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=C43SsUA5OCcbVBTaSANAj1vwibNoo1rJF1BpXIfZWW8=; b=m+xtx3RX34fCKSucQ8OCNTqH+tQZvodQCjYfQYukeFSUQDycuIfrZEX78BCOVWCXYN1UkiNtCLXlc7Sifn8hIozHioIDSZXv1R7VWd57xp1HIB/1ru+PJQg9nMYP1CpmY94dPhNfOVlF0J8OZV8gzQKfnjl0JVoW20sIQKabTVr5SVm8OyCVUFPuGQVgg8MBexFeTF/58DupId2lXmKNfgL3bgw4kiSiMNhQpxAZ5Ug+w1kPXQzI+ypobkcTGbGwVpSgz2Ax3hLi8jpVID3BS9L1nqp0a/ouD2l8ueskL1Nj2Pt+e2cLdBKG/0uwk5UfrFf1CYAy0mAjqB9sdOLhuw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1teBwp-000573-FM; Sat, 01 Feb 2025 06:46:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75981] [PATCH (WIP) v1.5 3/4] Add 'guix fork update'. Resent-From: 45mg <45mg.writes@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sat, 01 Feb 2025 11:46:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75981 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75981@debbugs.gnu.org Cc: Nicolas Graves , Tomas Volf <~@wolfsden.cz>, 45mg <45mg.writes@gmail.com>, Liliana Marie Prikler , Ricardo Wurmus , Attila Lendvai , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75981-submit@debbugs.gnu.org id=B75981.173841033119581 (code B ref 75981); Sat, 01 Feb 2025 11:46:03 +0000 Received: (at 75981) by debbugs.gnu.org; 1 Feb 2025 11:45:31 +0000 Received: from localhost ([127.0.0.1]:56718 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1teBwI-00055l-Tm for submit@debbugs.gnu.org; Sat, 01 Feb 2025 06:45:31 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:42000) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1teBwG-00055U-MY for 75981@debbugs.gnu.org; Sat, 01 Feb 2025 06:45:29 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-216395e151bso35162275ad.0 for <75981@debbugs.gnu.org>; Sat, 01 Feb 2025 03:45:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738410322; x=1739015122; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C43SsUA5OCcbVBTaSANAj1vwibNoo1rJF1BpXIfZWW8=; b=frY6YJvA4iv9rrm0t+t1Czox72gYk3SN3nGwlelnG/ceHiipxbz7kbwwR3MKNlrMab VBsCKRg36qzUWtNrFPJXh0kuP4PLnz/mkIjrCrKjs2XFZ+U5A2hX54aNJ/SK8OaG73e5 fy6DdjQLrvmL2HqGnlP4Pg9SobSPIbbnGIvvrRqZuWrFPwfPqWEB841Fj1G8WajqrvLJ CzULuuTTjDkThfQhbm7+oeXpRJeideaarHZmG4JQBea3j8MZgRkb33LvByuQLymvdxhb 4+UdC4KabT4wTWWu83k58Dy+DciKudrobMU3XpvvQO2EWypNejTKVpXNVEXhsp/jxaTi mIIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738410322; x=1739015122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C43SsUA5OCcbVBTaSANAj1vwibNoo1rJF1BpXIfZWW8=; b=YQB96j8eobyrwB5KC4BsQOQm7iSLgC3xe94i+Dw029KhhMxoDQdzCWTgqA4DuHfS0c OQPgcBBWUfMJndvSWximxc6Pg3bgfHVxh/X9QxSBTJ6ANAKymsWWO6Dwjvu+rRNXs0r1 X8iDc5Q9XkTMsUkTeoO7DiY+bz9LbKnK6kJOomWsCH7i1i2qjydD7SjJPwwWCb3DzEjU CatDL6j4Rr5uAI9TsAnmzt5yxhHM3bEvycqzcKSNGnVBtjAraWhWe9mUVcba7kjozBM8 HS+GVnvD6Vfm8U4va2TvnjAQWYfQfCgKUOL2g7wFcD1k4DhEPQDPi/goy0QEwufjbj/x WyVQ== X-Gm-Message-State: AOJu0YzDlTIoJTvaUkr3jXMSZtMufZDKdxM0zMDjvNt05M2FBonl5nMi IiBO1rs+BuvHi83+b/Jaotknm+O5GwGT9O5ZINrfNlfz07D6wNVEcF+hmacm X-Gm-Gg: ASbGncumiDxAHrCBM0oiuzbVRpqw4n5IWvKt1edaxFl3CLPr7EmDzvtgqYvlzRq7yGl 8BDiGVSrMkBfTyfsmCl2xyCA4CqSB7r9guY62D9G9oJkM9/Rh/litW6fvnK8SfKvc6dPL8Poziz EFEQPnbKBbIoj349rFLJ71mu9YRkTNUwProhg3wFmh/J3G0+o2gUr2u16txLQW9HeTWMiRP0fKV V71yLeSOUsr0+Ivq97Kql3NgDJBYkDkCSdJKT6BVxK03KfisT35NF2GZRXqSnXP+wpCPv1oY5Ff GYAX9RC3H2DxBM/GzzyCraTucv2mEYJ/HPJ2PQ== X-Google-Smtp-Source: AGHT+IFbwwKI7Pc2LIZzqmfu9wewH23RfB/o1GVHXun4PgPYResuPVdqO5rRLbnZC0Q2ZbmP/xcQSQ== X-Received: by 2002:a17:902:d486:b0:216:4676:dfb5 with SMTP id d9443c01a7336-21de19b09camr168965575ad.21.1738410322476; Sat, 01 Feb 2025 03:45:22 -0800 (PST) Received: from localhost.localdomain (utm3.nitt.edu. [14.139.162.2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21de331f8d4sm43844805ad.224.2025.02.01.03.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Feb 2025 03:45:22 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Sat, 1 Feb 2025 17:13:25 +0530 Message-ID: <20c828d43d189914c7a5a3de58831f74b134e796.1738408683.git.45mg.writes@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/fork/update.scm: New file. * Makefile.am (MODULES): Add the new file. * guix/scripts/fork.scm (show-help): Mention new command. (%sub-commands): Add new command. Change-Id: I2017eb9a9286c02ca8bdf962bcbfe89d7607c413 --- Makefile.am | 1 + guix/scripts/fork.scm | 4 +- guix/scripts/fork/update.scm | 182 +++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 guix/scripts/fork/update.scm diff --git a/Makefile.am b/Makefile.am index 1c1f5d84fd..8edd371ccd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -380,6 +380,7 @@ MODULES = \ guix/scripts/fork.scm \ guix/scripts/fork/create.scm \ guix/scripts/fork/authenticate.scm \ + guix/scripts/fork/update.scm \ guix/scripts/graph.scm \ guix/scripts/weather.scm \ guix/scripts/container.scm \ diff --git a/guix/scripts/fork.scm b/guix/scripts/fork.scm index c5c7a59ba7..bf9c86e0aa 100644 --- a/guix/scripts/fork.scm +++ b/guix/scripts/fork.scm @@ -32,6 +32,8 @@ (define (show-help) create set up a fork of Guix\n")) (display (G_ "\ authenticate authenticate a fork of Guix\n")) + (display (G_ "\ + update update a fork of Guix\n")) (newline) (display (G_ " -h, --help display this help and exit")) @@ -40,7 +42,7 @@ (define (show-help) (newline) (show-bug-report-information)) -(define %sub-commands '("create" "authenticate")) +(define %sub-commands '("create" "authenticate" "update")) (define (resolve-sub-command name) (let ((module (resolve-interface diff --git a/guix/scripts/fork/update.scm b/guix/scripts/fork/update.scm new file mode 100644 index 0000000000..4223b9855c --- /dev/null +++ b/guix/scripts/fork/update.scm @@ -0,0 +1,182 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Tomas Volf <~@wolfsden.cz> +;;; Copyright © 2025 45mg <45mg.writes@gmail.com> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix scripts fork update) + #:use-module (guix scripts fork authenticate) + #:use-module (git repository) + #:use-module (git structs) + #:use-module (git config) + #:use-module (guix ui) + #:use-module (guix scripts) + #:use-module ((guix utils) #:select (invoke/stdout)) ;TODO move invoke/stdout to (guix build utils) + #:use-module (guix build utils) + #:use-module (guix channels) + #:use-module (ice-9 exceptions) + #:use-module (ice-9 match) + #:use-module (ice-9 popen) + #:use-module (ice-9 pretty-print) + #:use-module (ice-9 string-fun) + #:use-module (ice-9 textual-ports) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-13) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-37) + #:use-module (srfi srfi-71) + #:export (guix-fork-update)) + +;;; Commentary: +;;; +;;; Update a fork of Guix created via `guix fork create` and authenticated via +;;; `guix fork authenticate`, by applying new commits from the upstream branch +;;; onto it. +;;; +;;; Code: + +(define %options + ;; Specifications of the command-line options. + (list (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix fork create"))) + + (option '( "fork-branch") #t #f + (lambda (opt name arg result) + (alist-cons 'fork-branch-name arg result))) + (option '(#\r "repository") #t #f + (lambda (opt name arg result) + (alist-cons 'directory arg result))))) + +(define %default-options + '()) + +(define %usage + (G_ "Usage: guix fork update [OPTIONS...] +Pull into this Guix fork's configured upstream branch, then apply new commits +onto the current branch. + + -r, --repository=DIRECTORY + Act in the Git repository in DIRECTORY + --fork-branch=BRANCH + Apply new commits onto BRANCH instead of the current + branch + + -h, --help display this help and exit + -V, --version display version information and exit +")) + +(define (show-help) + (display %usage) + (newline) + (show-bug-report-information)) + +(define (missing-arguments) + (leave (G_ "wrong number of arguments; \ +required ~%"))) + + +;;; +;;; Entry point. +;;; + +(define (guix-fork-update . args) + + (define options + (parse-command-line args %options (list %default-options) + #:build-options? #f)) + + (define (command-line-arguments lst) + (reverse (filter-map (match-lambda + (('argument . arg) arg) + (_ #f)) + lst))) + + (define-syntax invoke-git + (lambda (x) + (syntax-case x () + ((_ args ...) + #`(invoke "git" "-C" #,(datum->syntax x 'directory) args ...))))) + + (define-syntax invoke-git/stdout + (lambda (x) + (syntax-case x () + ((_ args ...) + #`(string-trim-right + (invoke/stdout "git" "-C" #,(datum->syntax x 'directory) args ...)))))) + + (with-error-handling + (let* ((directory (or (assoc-ref options 'directory) ".")) + (current-branch-name (invoke-git/stdout + "branch" + "--show-current")) + (current-head-location (invoke-git/stdout + "rev-parse" + "HEAD")) + (fork-branch-name (or (assoc-ref options 'fork-branch-name) + (if (string= current-branch-name "") + (leave (G_ "no current branch and --fork-branch not given")) + current-branch-name))) + + (repository (repository-open directory)) + (upstream-branch-name introduction-commit introduction-signer + (if (fork-configured? repository) + (fork-configured-introduction + (repository-open directory)) + (leave (G_ "fork not fully configured. +(Did you remember to run `guix fork authenticate` first?)%~")))) + (upstream-branch-commit + (invoke-git/stdout "rev-parse" upstream-branch-name)) + (new-upstream-branch-commit "") + (config (repository-config repository)) + (signing-key + (or + (catch 'git-error + (lambda () + (config-entry-value + (config-get-entry config "user.signingkey"))) + (const #f)) + (begin + (info (G_ "user.signingkey not set for this repository.~%")) + (info (G_ "Will attempt to sign commits with fork introduction key.~%")) + introduction-signer)))) + + (info (G_ "Pulling into '~a'...~%") upstream-branch-name) + (invoke-git "switch" upstream-branch-name) + (invoke-git "pull") + (set! new-upstream-branch-commit + (invoke-git/stdout "rev-parse" upstream-branch-name)) + + (info (G_ "Rebasing commits from '~a' to '~a' onto fork branch '~a'...~%") + upstream-branch-commit + new-upstream-branch-commit + fork-branch-name) + (invoke-git "rebase" "--rebase-merges" + (string-append "--gpg-sign=" signing-key) + fork-branch-name new-upstream-branch-commit) + + (info (G_ "Resetting fork branch '~a' to latest rebased commit...~%") + fork-branch-name) + (invoke-git "branch" "--force" fork-branch-name "HEAD") + + (invoke-git "checkout" (or current-branch-name current-head-location)) + + (info (G_ "Successfully updated Guix fork in ~a~%") + directory))))