From patchwork Fri Jan 31 21:18:46 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: 38073 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 8EBAA27BBEA; Fri, 31 Jan 2025 21:21:22 +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=ham 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 D442227BBE2 for ; Fri, 31 Jan 2025 21:21:21 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tdyRl-00088S-Gj; Fri, 31 Jan 2025 16:21:05 -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 1tdyRj-00087T-Ct for guix-patches@gnu.org; Fri, 31 Jan 2025 16:21:03 -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 1tdyRi-0002fn-Q8 for guix-patches@gnu.org; Fri, 31 Jan 2025 16:21:03 -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=+XspKeyjomk44e0/WIApWppbYgKqZm7vtWqBqkgLKjs=; b=rhsR9AZxf48PU6kVL1DpEk0vwAeu3gVDG4jpxh63vnboWv2yY6dUb1rrrpM6s6UqhTk4ZNrRm/xvHGTCsmFjXGOwpzZ5Mve4siJvsQOchXJHy9obHd9JNRhgev6w2u9fBXPXADDRIeQmy/d/8J6wed67F+1fSySUFxoBj6+ejVPlKRQJdtDL4FuwkVhIODa6hedAck3k1+XupMoxKtMIZTRmv8ZcZTiyFBgO5E5Jq+EFJ5WqSf09V34wC/PheM2VncRbwAkxpIPrDZ3FT3pfqHOo3j077VeVViDUKCYnUeUtoU0myRgUPnQJ/0DOwMLqJ+0QnesTZ3HL1QDH59zEhg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tdyRi-0005sX-KZ for guix-patches@gnu.org; Fri, 31 Jan 2025 16:21:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75981] [PATCH (WIP) v1 3/4] Add 'guix fork update'. Resent-From: 45mg <45mg.writes@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 31 Jan 2025 21:21:02 +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 Received: via spool by 75981-submit@debbugs.gnu.org id=B75981.173835841222193 (code B ref 75981); Fri, 31 Jan 2025 21:21:02 +0000 Received: (at 75981) by debbugs.gnu.org; 31 Jan 2025 21:20:12 +0000 Received: from localhost ([127.0.0.1]:54953 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tdyQt-0005l7-UL for submit@debbugs.gnu.org; Fri, 31 Jan 2025 16:20:12 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:61737) 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 1tdyQr-0005kQ-Cl for 75981@debbugs.gnu.org; Fri, 31 Jan 2025 16:20:10 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-21669fd5c7cso43783225ad.3 for <75981@debbugs.gnu.org>; Fri, 31 Jan 2025 13:20:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738358403; x=1738963203; 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=+XspKeyjomk44e0/WIApWppbYgKqZm7vtWqBqkgLKjs=; b=WN3ZvX4BM5x32buT4f9WgMP/X3Fw/FSvcXdxBbTtnQUvZjQwI0+4+bWHfrs2IQplCU 0PhSC4oVpuHZ4/IVeeUnun/oBgjiKR9IdToUNxESlM4bLCiB5sBa1K7avMoNNIc+Jj4s dloy/HY0wYg2R8neZ9pyk7XRa59R4LdpAx1PILmNp1bAXtx36C4po+EYTV0/A+H+vkXk ipOj4BLyCQDQvbITMF7vmDcBH/9CtI1ILVN8YbTX0/avYy59DRM5CdswyhMkWgW4MGG4 P9snyronE3oScSefiIKsTEPEZReDE3nwyFc05jMGZNg/vPGvzYZGbzODBpkChwp6YhjR CCsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738358403; x=1738963203; 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=+XspKeyjomk44e0/WIApWppbYgKqZm7vtWqBqkgLKjs=; b=QhPVs2VxnUEmOnJgI7TVA7vjmugWl8gje5yPc3qqa5iqSIhhQDg2Bm1YPaGi3CpYu8 4/uXlWuL4AsOPEtQIHvjubRepVqWeNFwOHwtsYlOMerjE4TVLm//nmwqwzdxoolzK4WN 7+JHB6EAQ+tk0FUNXJoojPXbwnNa72vY5GWWSls4rsmG5QL6K7/z78lunbiZjArj3HUP h59LqoXZP9hXpkHp1KZX6JkOskjOsLrU4ScU1CHn1yVOPmP/6dhjw19jmGb/rGH95htv Fn8raIIp+Wg2vOuIXhzSpjg4xaXTqC1x+Mv2nICC+CiWJp88XyqFfYUI0OWcRtoY94U4 MNBw== X-Gm-Message-State: AOJu0Ywr7MHG6v4C4hvvBWRvz+4Zvldva/3jfQ1V4v+NE7jR7wgun5xY NcMajEWAATau6zM3lZ27g0RoEEcp1n+KcP43g1/6i7qejAid1PyqPDJmm+4l X-Gm-Gg: ASbGncv7cBd7Q5JtUT9+3kbhF4L7NiuzdkON2+zTo8aR2TCEgwIbeJathPP8XNdZio0 +o/imU+BllZxpR6cXDRkVVyRoFtp7H9a2JpoARgStu1A0ZTWMuJQRgkxcX045qxZ1y5DlM00JWk rWJuGtTeHT6xU2M3FywJ8drbiIPKulJejYgSUnJSXKXWFasMEAgDTRW+N7h6+TI3G91Pis5XzgX Qj9vDO9YxG0TgFSHdlumLBpbt3PHb4zGE1feomADVL2HsUMWVrV8TrOhVfJzWAo+QUozZf6v9FH gE9TMzPGPwV5MN/S0wdevHvxENxOAgIlb1IxOg== X-Google-Smtp-Source: AGHT+IFuPwf+hRwCp1jyv0amn0b8uDVXPs1L12kBLRKlcDR+W4P1f35RRYEbXR5K2ea+nOOHqSxyxQ== X-Received: by 2002:a05:6a00:e8a:b0:72a:bc6a:3a87 with SMTP id d2e1a72fcca58-72fd096a0a5mr18685827b3a.0.1738358403090; Fri, 31 Jan 2025 13:20:03 -0800 (PST) Received: from localhost.localdomain (utm3.nitt.edu. [14.139.162.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72fe64275c4sm3924008b3a.61.2025.01.31.13.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2025 13:20:02 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Sat, 1 Feb 2025 02:48:46 +0530 Message-ID: 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 | 181 +++++++++++++++++++++++++++++++++++ 3 files changed, 185 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..5aed337b85 --- /dev/null +++ b/guix/scripts/fork/update.scm @@ -0,0 +1,181 @@ +;;; 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 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))))