From patchwork Fri Oct 21 15:13:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75DBDC43219 for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbiJUPOF (ORCPT ); Fri, 21 Oct 2022 11:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbiJUPNr (ORCPT ); Fri, 21 Oct 2022 11:13:47 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED22124A575 for ; Fri, 21 Oct 2022 08:13:45 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id a3so5467224wrt.0 for ; Fri, 21 Oct 2022 08:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=pKtxY62K0AkC/Kytym1KJ2VlVW72vK4Z2r9tgOTQi+o=; b=mza6cSF8sFMKwOsXq/1ydKzNlGORjHV4tZrcnPeB4ESlwIMDgZI2FQikoe+pPpasb9 bcSFX74keATIjuI3EzJieheoKoRW4wFzp/ZEv3nhZqU7Ga0gglsb+4Ovw182g+dVqThT F7Uqxl2fhKPAn5IJOKNhPwNPMt6gL8Llh7S6vDAoxMqjjv6vW0IzNu2UB+UUH3NQmTy7 uHkuJRFlilr07xIM8QhDmxDSf3/9MRurGSquxcOb5q3Nd7UAc0XL1v6mWeWuRgoy36of B7pca1QC+UJnb05CCOoM1yuKg8b5z0gX4YiRJAQndKRYcOflmNoZ1pA4FA1w5t9f4C3G HOpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pKtxY62K0AkC/Kytym1KJ2VlVW72vK4Z2r9tgOTQi+o=; b=XrXlqnuC2LLDyWmalVt+cz2upZJNUMtMbPyJhiOz0VTG+hXE61YoTsb6jhvod8/NWg 4nWu6buRibslVCzFFYRNT5lTqZsVoMvLDcE4wG7R910LlZ2FAxVuz5ipBVQ+ObeVnumG /sgurMuo3l2v1IcT2ttXhRWlEb98fJ5PMLctTldVIJrfithQvhppXCbcxN9mCEEnWvFq Sjvc5odN8cCTGheMzWDVAhwUDkXS91LOCMieQMcKs+d6alHXFlULqeVO9i44WGqUxZLe jHeX0v65btWnmX4uIfP5VmiKqExAvJ6g1eWTGEe5fPw00oX2dPn3SpC58nKznf5HC0fL CsxA== X-Gm-Message-State: ACrzQf1f0Xq/60znyyvcZYZGbjNqunPRX2GU7eQgJcmw9R8VBt25FVjO BOJ9cYc4/2/OS/h/XGIi9YSuUX130FQ= X-Google-Smtp-Source: AMsMyM4SgRFwm3bFemcBWUu7LxmFx0mz+PF3KX8kXYbYAFTpeNc50AT3JF1qkmIfCvoWcwNYSGYLng== X-Received: by 2002:a5d:4c43:0:b0:236:547f:bd3c with SMTP id n3-20020a5d4c43000000b00236547fbd3cmr2491814wrt.380.1666365224315; Fri, 21 Oct 2022 08:13:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v1-20020adfedc1000000b00228daaa84aesm19483926wro.25.2022.10.21.08.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:43 -0700 (PDT) Message-Id: <832e910aadc47309392feed69927c2e8693cbfc5.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:31 +0000 Subject: [PATCH 1/9] test-lib-functions: mark 'test_commit' variables as 'local' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Some variables in 'test_commit' have names that are common enough that it is very likely that test authors might use them in a test. If they do so and use 'test_commit' between setting such a variable and using it, the variable value from 'test_commit' will leak back into the test and most likely break it. Prevent that by marking all variables in 'test_commit' as 'local'. This allow a subsequent commit to use a 'tag' variable. Signed-off-by: Philippe Blain --- t/test-lib-functions.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 527a7145000..adc0fb6330c 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -273,13 +273,13 @@ debug () { # , , and all default to . test_commit () { - notick= && - echo=echo && - append= && - author= && - signoff= && - indir= && - tag=light && + local notick= && + local echo=echo && + local append= && + local author= && + local signoff= && + local indir= && + local tag=light && while test $# != 0 do case "$1" in @@ -322,7 +322,7 @@ test_commit () { shift done && indir=${indir:+"$indir"/} && - file=${2:-"$1.t"} && + local file=${2:-"$1.t"} && if test -n "$append" then $echo "${3-$1}" >>"$indir$file" From patchwork Fri Oct 21 15:13:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AC53C4167B for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbiJUPOI (ORCPT ); Fri, 21 Oct 2022 11:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbiJUPNt (ORCPT ); Fri, 21 Oct 2022 11:13:49 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08A610DE41 for ; Fri, 21 Oct 2022 08:13:47 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id bp11so4999443wrb.9 for ; Fri, 21 Oct 2022 08:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=dQg2Yh/C6qTRM4fuzX0XO0sGqNk7vg22JFBcSfkd4yo=; b=nATpSTs3TETlqLBiHCxclHRLTJgI12pZV5NSpdy5Bnh6sJWQoXzAI2frHiMExejCgi U39ggIA20+nPyzOibYojC0JTGmPCfrriAH3QpPBz5+GsjffupC4jVegVtd1om3ZK30lK wGbmxQENZSEVwoIIrO/ZZrxZ7F6QFl80Cz7SRF0wZblt1qpM9z7UKKD85/l8Wsm45wzG yu8i/lWFf+ayFCZobqjzFzcL7j+RE2ZXdSqBjagy9bUGYJoIvM0MlNAWtwGIRvmDu2N+ Ak3oUcKAvHQFdEN1N0J+WQfFzqHrSFWUEmPqyl2Pg8cheL5IXinoT/n7HtT27vxe7Kz2 Gh9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dQg2Yh/C6qTRM4fuzX0XO0sGqNk7vg22JFBcSfkd4yo=; b=qJKE7y+9BLAoRuBot89j4XTAsFNPxNiIykpwqdthNiPnrQU94xdS44/Tv7qnRmT9wF KPY+cKzykJbb/PssVBc67JVMKoyGqyNxsic+OyXzYRH4nSv+dzQJUvVpy+DOu8W4QbyX /VG+oP96un5mqLut8QX1VbawduLrEUpRheesf5G88/46Si6432oywvN1XhBBNJiCfMNs OJisMqoQ1KlbGNKtUhTe7+1aDPyyLTmf1YShq45qt3KALCQNbYz90pyJzYYs4HFAQkqk hQ4vssX0ZJ8q3gs4NNsDog5kNHkoGriB7X9iIas3+bTbOzodd3jJAc4Gw3DJ4r+cWKAD cqHw== X-Gm-Message-State: ACrzQf38z5YXDQZsshEdjbTxkYkflR1mXOpOXPjLPu1gmv7tcJUsPOT3 j4t51bg/3bs6JUh1kCPaL2Hjip32sP0= X-Google-Smtp-Source: AMsMyM4Q9KA1MAjS/xtDLksx7k6eYsKCUSPgv3/gHgJmCAgQnWPlqaKZHN6nhKWholA9K7Hslh90Lg== X-Received: by 2002:a5d:590d:0:b0:236:4ddd:1869 with SMTP id v13-20020a5d590d000000b002364ddd1869mr4202596wrd.709.1666365226035; Fri, 21 Oct 2022 08:13:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b7-20020adfe307000000b0022cbf4cda62sm23319113wrj.27.2022.10.21.08.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:45 -0700 (PDT) Message-Id: <040bc2224c9e42fb8d6fe6d2c01fcbe57a938613.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:32 +0000 Subject: [PATCH 2/9] subtree: use 'git rev-parse --verify [--quiet]' for better error messages Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain There are three occurences of 'git rev-parse ' in 'git-subtree.sh' where the command expects a revision and the script dies or exits if the revision can't be found. In that case, the error message from 'git rev-parse' is: $ git rev-parse fatal: ambiguous argument '': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' This is a little confusing to the user, since this error message is outputed by 'git subtree'. At these points in the script, we know that we are looking for a single revision, so be explicit by using '--verify', resulting in a little better error message: $ git rev-parse --verify fatal: Needed a single revision In the two occurences where we 'die' if 'git rev-parse' fails, 'git subtree' outputs "could not rev-parse split hash $b from commit $sq", so we actually do not need the supplementary error message from 'git rev-parse'; add '--quiet' to silence it. In the third occurence, we 'exit', so keep the error message from 'git rev-parse'. Note that this messsage is still suboptimal since it can be understood to mean that 'git rev-parse' did not receive a single revision as argument, which is not the case here: the command did receive a single revision, but the revision is not resolvable to an available object. The alternative would be to use '--' after the revision, as suggested by the first error message, resulting in a clearer error message: $ git rev-parse -- fatal: bad revision '' Unfortunately we can't use that syntax because in the more common case of the revision resolving to a known object, the command outputs the object's hash, a newline, and the dashdash, which breaks the 'git subtree' script. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 7562a395c24..49ef493ef92 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -387,7 +387,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) @@ -439,7 +439,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) @@ -843,7 +843,7 @@ cmd_add_commit () { git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? - headrev=$(git rev-parse HEAD) || exit $? + headrev=$(git rev-parse --verify HEAD) || exit $? if test -n "$headrev" && test "$headrev" != "$rev" then headp="-p $headrev" From patchwork Fri Oct 21 15:13:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B6F8C43217 for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiJUPOH (ORCPT ); Fri, 21 Oct 2022 11:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbiJUPNu (ORCPT ); Fri, 21 Oct 2022 11:13:50 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 092EE196ED1 for ; Fri, 21 Oct 2022 08:13:49 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id y10so2425966wma.0 for ; Fri, 21 Oct 2022 08:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=vTg1txQOsit9YnJUOpD+dDLtJr9/8lm1SMxzQ9uFOAQ=; b=ZvH53AeHfKv9fiXumg3cr47vv1wOGE+nk3XXZcxzgmoW1ZXuF86S9+MKxJ9jFSUcAB 3B+mhbqJrdj0no0XE4KgSYSh89W3OFVMxpEgYQh6+7YI2/ef9wDj5feDqaWAKkejcunP ITDtW0hgKyGpmanDxBAomzTOrJAD7CiSeLbXh/Zw/bSKYiuU4mH0Iw/nStTuNjCepYmr 0kkmfgjAlabKwfg3IDZmcUtbTibMt2RVADLFHqeDN9vP9KP03Im+6CGOvB+RfSWTZ43r fiIOQ1MCtZBAUA7OitHJNvWjoMlMBx3hJA9liUwjJxoyxblYhLaBnh88T8f3HHDQctD3 7CyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vTg1txQOsit9YnJUOpD+dDLtJr9/8lm1SMxzQ9uFOAQ=; b=CSkBEE0ORrWYvQqL9nK2AsgVZ4VUeiwGgTCAOd9JSx/U7UaGdonOtaVegkVjO2kCIC UboM5FzbxctLE4wN6Qo1FowB8QLOKRk9RPjD+7awpJSac0gkreMdZo1ejt35K4IoWcC6 0jygmyye8DzTUp8L1kG7MjSi+GI/RNj9rxzP6YCqqbXt7vxN2h48GtsJvcQ0EoRRu5WS 13FBcI2koWTO2yqSAfRCJ7Z/hM1VraQWOUmU/ZKIWbs/3ZOxuaB6tVD+uB9oeAT12R8g dW8FCNu6ckHHgoUH7+5x3eSo+N5AhXmD6oFVSvh7HYe9rp5Aym0wXAsT4mCD6gLckHhK PwZQ== X-Gm-Message-State: ACrzQf2yH5Bcqe9GFUs1c9FEvijfopJFIzu60qgGOQMHdjj3p199tKt4 zyq6wgh93UQd8rerKwl6zTCojKKCioc= X-Google-Smtp-Source: AMsMyM5Nx8Z9QYK5mjU620bVwvGDNBJ//ePpH0xjfNARnK/x/JHVdEEPmjs0E2oJOpNf28A/IBvODg== X-Received: by 2002:a05:600c:5011:b0:3c6:cd93:cf24 with SMTP id n17-20020a05600c501100b003c6cd93cf24mr13244102wmr.16.1666365227370; Fri, 21 Oct 2022 08:13:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y15-20020a056000108f00b0023647841c5bsm3863678wrw.60.2022.10.21.08.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:46 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:33 +0000 Subject: [PATCH 3/9] subtree: add 'die_incompatible_opt' function to reduce duplication Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain 9a3e3ca2ba (subtree: be stricter about validating flags, 2021-04-27) added validation code to check that options given to 'git subtree ' made sense with the command being used. Refactor these checks by adding a 'die_incompatible_opt' function to reduce code duplication. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 49ef493ef92..f5eab198c80 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -102,6 +102,14 @@ assert () { fi } +# Usage: die_incompatible_opt OPTION COMMAND +die_incompatible_opt () { + assert test "$#" = 2 + opt="$1" + arg_command="$2" + die "The '$opt' flag does not make sense with 'git subtree $arg_command'." +} + main () { if test $# -eq 0 then @@ -176,16 +184,16 @@ main () { arg_debug=1 ;; --annotate) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_annotate="$1" shift ;; --no-annotate) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_annotate= ;; -b) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_branch="$1" shift ;; @@ -194,7 +202,7 @@ main () { shift ;; -m) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_message="$1" shift ;; @@ -202,34 +210,34 @@ main () { arg_prefix= ;; --onto) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_onto="$1" shift ;; --no-onto) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_onto= ;; --rejoin) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" ;; --no-rejoin) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" ;; --ignore-joins) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_ignore_joins=1 ;; --no-ignore-joins) - test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command" arg_split_ignore_joins= ;; --squash) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_squash=1 ;; --no-squash) - test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_squash= ;; --) From patchwork Fri Oct 21 15:13:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA11BC4321E for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230189AbiJUPOK (ORCPT ); Fri, 21 Oct 2022 11:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbiJUPNx (ORCPT ); Fri, 21 Oct 2022 11:13:53 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6590110DE41 for ; Fri, 21 Oct 2022 08:13:50 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id f11so4892961wrm.6 for ; Fri, 21 Oct 2022 08:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ut+xy5XYlXlpAwbLAcjtmwQZAsBzHKwqZnS6hCBqI7M=; b=Dlfp05HiMINYHxuV/DrInGRaJLAVY/ReNXnrfIpK31HL1npMf6feRp4eLcOz8l2IfB LgrwnZYyCXNjryOQSASpy2uH6VcJaUfRWeAeUynBtqw73gXo0ZH1t0G0LTJ1bONr01UP ket8DT6OCjxL3WOeBX0WbW5TidaHtqWIN9cJFpUCDsFBF09LkIgVJzsOsWX7JX8owqOg 9thTgyhQETI6YgmURMQq/8ck8dHFbY16eNS6txt/4hKbgYrnzWl9e6CcUl866j6z5yWx SDnKHYrLMclsA/lN88fRpfEj7Y995u9URqV1Ajt8qrBzqlUuaebfrWdNbmdxtA2Ez63H zAkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ut+xy5XYlXlpAwbLAcjtmwQZAsBzHKwqZnS6hCBqI7M=; b=gv51wMw36m+5PM4muYgggjceSEYXEcsT4GNvK/HHvRH+M/uCpJef8MwXGCTVaBg6V7 Sxwq4t6WP6FiQQt2NCbjXFCv9spqJdYTl9Mbf0RvyuNXRKWx/c+apev2XneIs8t6ZWzq OVLDHzPmp/iaPasF9alrW/r1NsWbojjWNv/VkxSMZ0u15ayfAK0ZteVVI2nw4MJ1s6Kh 3YO4NGJzcJvNHEx5kPD8xY4PLw2bGR/HwL3eRiupx+gbi2CkB+9vEwpEAe9yLNbT7a0v 7zpQTe5fOX66C6dCE5QychuvXHASPf5xC9WGUQM7bVxuB1M9pws+XVFb8963fuKRKOba MH3A== X-Gm-Message-State: ACrzQf03Jo7OZ1nkYQAyypj8Cs8l5jSmHMYb819u+4sBqP2wjM5czC+3 jrjP1zhCSo9WAmlBUhISkJqYd5sxMJM= X-Google-Smtp-Source: AMsMyM4iqE/acKvVQ9v1eJ2J3cFVcIHUeIWKLThIlLCV+6NE5k7BU55wBHekAL5Cqx7eHAe5PYh+3Q== X-Received: by 2002:a5d:64e2:0:b0:22e:7060:b4a7 with SMTP id g2-20020a5d64e2000000b0022e7060b4a7mr12085632wri.129.1666365228561; Fri, 21 Oct 2022 08:13:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j8-20020a05600c1c0800b003c6b7f5567csm10662030wms.0.2022.10.21.08.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:48 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:34 +0000 Subject: [PATCH 4/9] subtree: prefix die messages with 'fatal' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Just as was done in 0008d12284 (submodule: prefix die messages with 'fatal', 2021-07-10) for 'git-submodule.sh', make the 'die' messages outputed by 'git-subtree.sh' more in line with the rest of the code base by prefixing them with "fatal: ", and do not capitalize their first letter. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 60 +++++++++++++++--------------- contrib/subtree/t/t7900-subtree.sh | 12 +++--- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index f5eab198c80..89f1eb756f0 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -98,7 +98,7 @@ progress () { assert () { if ! "$@" then - die "assertion failed: $*" + die "fatal: assertion failed: $*" fi } @@ -107,7 +107,7 @@ die_incompatible_opt () { assert test "$#" = 2 opt="$1" arg_command="$2" - die "The '$opt' flag does not make sense with 'git subtree $arg_command'." + die "fatal: the '$opt' flag does not make sense with 'git subtree $arg_command'." } main () { @@ -155,7 +155,7 @@ main () { allow_addmerge=$arg_split_rejoin ;; *) - die "Unknown command '$arg_command'" + die "fatal: unknown command '$arg_command'" ;; esac # Reset the arguments array for "real" flag parsing. @@ -244,7 +244,7 @@ main () { break ;; *) - die "Unexpected option: $opt" + die "fatal: unexpected option: $opt" ;; esac done @@ -252,17 +252,17 @@ main () { if test -z "$arg_prefix" then - die "You must provide the --prefix option." + die "fatal: you must provide the --prefix option." fi case "$arg_command" in add) test -e "$arg_prefix" && - die "prefix '$arg_prefix' already exists." + die "fatal: prefix '$arg_prefix' already exists." ;; *) test -e "$arg_prefix" || - die "'$arg_prefix' does not exist; use 'git subtree add'" + die "fatal: '$arg_prefix' does not exist; use 'git subtree add'" ;; esac @@ -282,11 +282,11 @@ cache_setup () { assert test $# = 0 cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" || - die "Can't delete old cachedir: $cachedir" + die "fatal: can't delete old cachedir: $cachedir" mkdir -p "$cachedir" || - die "Can't create new cachedir: $cachedir" + die "fatal: can't create new cachedir: $cachedir" mkdir -p "$cachedir/notree" || - die "Can't create new cachedir: $cachedir/notree" + die "fatal: can't create new cachedir: $cachedir/notree" debug "Using cachedir: $cachedir" >&2 } @@ -342,7 +342,7 @@ cache_set () { test "$oldrev" != "latest_new" && test -e "$cachedir/$oldrev" then - die "cache for $oldrev already exists!" + die "fatal: cache for $oldrev already exists!" fi echo "$newrev" >"$cachedir/$oldrev" } @@ -396,7 +396,7 @@ find_latest_squash () { ;; git-subtree-split:) sub="$(git rev-parse --verify --quiet "$b^{commit}")" || - die "could not rev-parse split hash $b from commit $sq" + die "fatal: could not rev-parse split hash $b from commit $sq" ;; END) if test -n "$sub" @@ -448,7 +448,7 @@ find_existing_splits () { ;; git-subtree-split:) sub="$(git rev-parse --verify --quiet "$b^{commit}")" || - die "could not rev-parse split hash $b from commit $sq" + die "fatal: could not rev-parse split hash $b from commit $sq" ;; END) debug "Main is: '$main'" @@ -498,7 +498,7 @@ copy_commit () { cat ) | git commit-tree "$2" $3 # reads the rest of stdin - ) || die "Can't copy commit $1" + ) || die "fatal: can't copy commit $1" } # Usage: add_msg DIR LATEST_OLD LATEST_NEW @@ -726,11 +726,11 @@ ensure_clean () { assert test $# = 0 if ! git diff-index HEAD --exit-code --quiet 2>&1 then - die "Working tree has modifications. Cannot add." + die "fatal: working tree has modifications. Cannot add." fi if ! git diff-index --cached HEAD --exit-code --quiet 2>&1 then - die "Index has modifications. Cannot add." + die "fatal: index has modifications. Cannot add." fi } @@ -738,7 +738,7 @@ ensure_clean () { ensure_valid_ref_format () { assert test $# = 1 git check-ref-format "refs/heads/$1" || - die "'$1' does not look like a ref" + die "fatal: '$1' does not look like a ref" } # Usage: process_split_commit REV PARENTS @@ -804,7 +804,7 @@ cmd_add () { if test $# -eq 1 then git rev-parse -q --verify "$1^{commit}" >/dev/null || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" cmd_add_commit "$@" @@ -819,7 +819,7 @@ cmd_add () { cmd_add_repository "$@" else - say >&2 "error: parameters were '$*'" + say >&2 "fatal: parameters were '$*'" die "Provide either a commit or a repository and commit." fi } @@ -882,9 +882,9 @@ cmd_split () { elif test $# -eq 1 then rev=$(git rev-parse -q --verify "$1^{commit}") || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" else - die "You must provide exactly one revision. Got: '$*'" + die "fatal: you must provide exactly one revision. Got: '$*'" fi if test -n "$arg_split_rejoin" @@ -927,7 +927,7 @@ cmd_split () { latest_new=$(cache_get latest_new) || exit $? if test -z "$latest_new" then - die "No new revisions were found" + die "fatal: no new revisions were found" fi if test -n "$arg_split_rejoin" @@ -948,7 +948,7 @@ cmd_split () { then if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new" then - die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'." + die "fatal: branch '$arg_split_branch' is not an ancestor of commit '$latest_new'." fi action='Updated' else @@ -965,9 +965,9 @@ cmd_split () { # Usage: cmd_merge REV cmd_merge () { test $# -eq 1 || - die "You must provide exactly one revision. Got: '$*'" + die "fatal: you must provide exactly one revision. Got: '$*'" rev=$(git rev-parse -q --verify "$1^{commit}") || - die "'$1' does not refer to a commit" + die "fatal: '$1' does not refer to a commit" ensure_clean if test -n "$arg_addmerge_squash" @@ -975,7 +975,7 @@ cmd_merge () { first_split="$(find_latest_squash "$dir")" || exit $? if test -z "$first_split" then - die "Can't squash-merge: '$dir' was never added." + die "fatal: can't squash-merge: '$dir' was never added." fi set $first_split old=$1 @@ -1003,7 +1003,7 @@ cmd_merge () { cmd_pull () { if test $# -ne 2 then - die "You must provide " + die "fatal: you must provide " fi ensure_clean ensure_valid_ref_format "$2" @@ -1015,7 +1015,7 @@ cmd_pull () { cmd_push () { if test $# -ne 2 then - die "You must provide " + die "fatal: you must provide " fi if test -e "$dir" then @@ -1030,13 +1030,13 @@ cmd_push () { fi ensure_valid_ref_format "$remoteref" localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") || - die "'$localrevname_presplit' does not refer to a commit" + die "fatal: '$localrevname_presplit' does not refer to a commit" echo "git push using: " "$repository" "$refspec" localrev=$(cmd_split "$localrev_presplit") || die git push "$repository" "$localrev":"refs/heads/$remoteref" else - die "'$dir' must already exist. Try 'git subtree add'." + die "fatal: '$dir' must already exist. Try 'git subtree add'." fi } diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 1c1f76f04aa..249743ab9aa 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -277,7 +277,7 @@ test_expect_success 'split requires option --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_fail git subtree split >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -296,7 +296,7 @@ test_expect_success 'split requires path given by option --prefix must exist' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -570,7 +570,7 @@ test_expect_success 'pull requires option --prefix' ' cd "$test_count" && test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_be_empty out && test_cmp expected err ) @@ -584,7 +584,7 @@ test_expect_success 'pull requires path given by option --prefix must exist' ' ( test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err && - echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_be_empty out && test_cmp expected err ) @@ -643,7 +643,7 @@ test_expect_success 'push requires option --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "You must provide the --prefix option." >expected && + echo "fatal: you must provide the --prefix option." >expected && test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && @@ -662,7 +662,7 @@ test_expect_success 'push requires path given by option --prefix must exist' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && + echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && From patchwork Fri Oct 21 15:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBFA9C4167D for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbiJUPOM (ORCPT ); Fri, 21 Oct 2022 11:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbiJUPNx (ORCPT ); Fri, 21 Oct 2022 11:13:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DADA2244729 for ; Fri, 21 Oct 2022 08:13:51 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id m29-20020a05600c3b1d00b003c6bf423c71so5265731wms.0 for ; Fri, 21 Oct 2022 08:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=x8nq8zpDnmWdA5GhrfzRibGRGzRLGdBhJfz5SbOmGdc=; b=osn/P6MQiFdJ/znUfOJ58jx2dU0QrApn14TUYqC2feVYGNaMPQbQWABL3ZBF3PUAnW oR4BTAjA9dFLwachJ/0YT7efX/U0VRpnVC4FZ1wV5S8UFo34H06dxvr/UJ4T8QukFtxa S/w6xIyXmK3nWbV5h7YMYMFvvGNkdeiZPcyraWeOECFQzGM4ud8psDWr4f3mxT0hw148 ZiSOcjwjFSqpq9urooatvM9H8PjD0i/iNPFigg32jS5kDnmmshHqDPf9nqx21L1BXSrq ASusjwACj0dZ4hESH3OybCCvG0tjVMM8UhbfQmmTAHJqZgLN3/DzQmXvFGboBF51OAx8 gS3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x8nq8zpDnmWdA5GhrfzRibGRGzRLGdBhJfz5SbOmGdc=; b=VcrpjYp/QSfZEeqJdcUGflhEXnRUygSZ3TRfS2fmzwlNvgoMsYNNRhQI/StlhErp1Y xal16iDTXOQzKqgu9VcrFeyvsnQV1XpTrXEKbCv7TWvU4g7h6ltayt0eZs0rLRPwUMXj gt5Yutr1LHrlQILT5Cq6nKRJUkziMTpbMKdA/zKU1chxoCfhNg6cStNPB2kTA31UnYxL 0NDptAnuHhjSDSDjUpPzEB450PQSJiVRWy+8agL4yXcPRIM1IeBitLBzpkFe9RVNM4S8 y9caWAaajJOVPalz2EDtAUyO85k/ggGyI9SQt9wesq7Zc8KpDBiZpiaPUTAyJu4U1eq7 /lOA== X-Gm-Message-State: ACrzQf2Xqu9B6Qu3yb2Cl6kvWaIO1OiMLCtWDSyy7Nq2FcPYyZhmK/LR vnQGEw6rlkxPkdDAsgtCueBx+94bRUU= X-Google-Smtp-Source: AMsMyM5ZuavNa0sh6vSjU33KuQHJudFxiwoJ1VHJ9g+8/xEkEYujEWHAUm8TXfQauZ9l8KUkpp0ITA== X-Received: by 2002:a05:600c:a08:b0:3bc:eb4c:b90 with SMTP id z8-20020a05600c0a0800b003bceb4c0b90mr13615489wmp.184.1666365230199; Fri, 21 Oct 2022 08:13:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d12-20020adfa40c000000b0022ca921dc67sm18678918wra.88.2022.10.21.08.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:49 -0700 (PDT) Message-Id: <200f7341c91df2cd616cbc4bdcd8025bed3af7ea.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:35 +0000 Subject: [PATCH 5/9] subtree: define a variable before its first use in 'find_latest_squash' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain The function 'find_latest_squash' takes a single argument, 'dir', but a debug statement uses this variable before it takes its value from $1. This statement thus gets the value of 'dir' from the calling function, which currently is the same as the 'dir' argument, so it works but it is confusing. Move the definition of 'dir' before its first use. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 89f1eb756f0..d91a9679075 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -374,10 +374,10 @@ try_remove_previous () { # Usage: find_latest_squash DIR find_latest_squash () { assert test $# = 1 + dir="$1" debug "Looking for latest squash ($dir)..." local indent=$(($indent + 1)) - dir="$1" sq= main= sub= From patchwork Fri Oct 21 15:13:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CEEDC433FE for ; Fri, 21 Oct 2022 15:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbiJUPOe (ORCPT ); Fri, 21 Oct 2022 11:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiJUPOF (ORCPT ); Fri, 21 Oct 2022 11:14:05 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26DC124A55A for ; Fri, 21 Oct 2022 08:14:03 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id a10so4827655wrm.12 for ; Fri, 21 Oct 2022 08:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=JCv6/p3ecQFKtTnCgpFOgTIHGb+AYBU4emdCsGw+pEw=; b=I/X0GQO7nSULS7JeGAQRNQDmFiAmzArrUrn9LjyKDH6UP1cAaV3USq38ZR3Dq0x7dc VdKspF/5zNGzd7m4fcWCgv+sbQkyWgSf7eIzqzRz3QLp4O1u00o9tjKPYBPGX0UO5uvA YAwta0asssDmXkj/KjwWs/CR9Na9CDlF1ziQPRIiT2IUblcUe9TKEKF74xNO66Nwv/z6 x69RwMBzJF5iyOMlrrdRksjNOuM4vyvvL7ud0KeiscexmvcZpbXfdv1WG1f0XTMA8hXJ IVpObIS9gKi6msWu+o7SMAGs+ZmxVvZcn+OPp/TN9Rdjum8+dFM4f+dLbazpri6iP3ax d29g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JCv6/p3ecQFKtTnCgpFOgTIHGb+AYBU4emdCsGw+pEw=; b=sKi7ZxjDQbJsbH8cN9RO8ox2etO6akr9RmRFTjrjZ9Rkx3BsdPfQlnLd6mqJocXGrB CM1epCw52Ka7VLIBwV8neBxwEYgRyUGGhw4Hr8dHuSlYSDqGUEh9tBPCETem8Bkp41gF E/9fvOQNSQoAGZXyYtly2y+yk1RqV/q7U1uwp5af3acmnLhGoxQE+zywt8+U1DNJ+Dw9 BSA6sgTWb1tmi0lUjPDWEuq/QGCUFI0UhnHJq7esaavT6+5SpuUa2HWlcvknCHBxz4Pk SijKI5nIvWRWO6CaFQYgQMeayQ1XtX2YVuAE9gP/fIlVPZJ55IoUfzioLAlg2SNITraT gaLQ== X-Gm-Message-State: ACrzQf3W5Z9j4xzMT4wrZ8dr/N3Sm6lgA74DfouNqy8mUCyHmeNmdd4R OpGid6mgXqxejNRvGqscc12LRv3DDQ4= X-Google-Smtp-Source: AMsMyM4/hfYoOD6yJYi+bg1FMFf5ptamHhx6+WNU29nehz2ptJJUh/LFqO9M/AEkXA4DPfdUEDsK1A== X-Received: by 2002:a5d:4050:0:b0:22c:dfcc:675b with SMTP id w16-20020a5d4050000000b0022cdfcc675bmr11932617wrp.105.1666365231231; Fri, 21 Oct 2022 08:13:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p63-20020a1c2942000000b003c6c5a5a651sm2789539wmp.28.2022.10.21.08.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:50 -0700 (PDT) Message-Id: <429b3656f503785b60297ace4f83fcceb7363a4c.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:36 +0000 Subject: [PATCH 6/9] subtree: use named variables instead of "$@" in cmd_pull Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain 'cmd_pull' already checks that only two arguments are given, 'repository' and 'ref'. Define variables with these names instead of using the positional parameter $2 and "$@". This will allow a subsequent commit to pass 'repository' to 'cmd_merge'. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index d91a9679075..2b3c429991b 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -1005,9 +1005,11 @@ cmd_pull () { then die "fatal: you must provide " fi + repository="$1" + ref="$2" ensure_clean - ensure_valid_ref_format "$2" - git fetch "$@" || exit $? + ensure_valid_ref_format "$ref" + git fetch "$repository" "$ref" || exit $? cmd_merge FETCH_HEAD } From patchwork Fri Oct 21 15:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDA7BC41535 for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230243AbiJUPON (ORCPT ); Fri, 21 Oct 2022 11:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbiJUPNy (ORCPT ); Fri, 21 Oct 2022 11:13:54 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1187D57276 for ; Fri, 21 Oct 2022 08:13:53 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id f11so4893314wrm.6 for ; Fri, 21 Oct 2022 08:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=7YKNED0AztI6diCfFFOuJ24JT2EwI8iBZ4rE/4egy3c=; b=N8MIM2ZZfZw48dRea25nyY/tRdCNrMoQQMWNykgQj8P0PYVufngJD5UlvPqaqbPP8X It74DLCUFkqgeP62EE9rOkyzjSq6xhDoXJ7ci15Q6OH7aHrlxKA+D6OHnzFrRjx3Hty0 Bu+VRQ3WmDTL08Eqf0IyQjddlpaDpgy8HqyTY81fKESXsYjGzLyxKWitIzb6Td45K57l ANKtRLjPADsxNwe0kMvL0SFadeHljcoxcfyDikOinLgs/LrOy68slz1rfFKtk/8Q0jYu 6mPtxuVrbx27//G5TQjzPBeO1kMTZvyaqtONCyLgmvbMs81sxMYo1Gqri4qowbyc32tI 2N7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7YKNED0AztI6diCfFFOuJ24JT2EwI8iBZ4rE/4egy3c=; b=RCuOBSYARmfBeshYef/Vp49Xi6M//e46J916tFawmV1xm1K7jq4MmW4RkdpE8xJovE r6cPuvi+UWMdk7TTdyvZotR6whZLYEzgvQISpzzZhKSNCbc2/mMDzhmGdkS+5GHKlKQi lIauxjkw7bdzqeDSHfYHIdg9sldablIq6W8TJMj0b+Lho1pGd1fcxfxTcynqvaNs6CKB 3Xcr4igqhS4z9KRzlexAOUAgaNgjEoLx00uKF+jhDdqHGi8cRIwtY/6SYdof8noT+XES POWyUF9/QHR1QoQoMm/wgWn3HPtfAcn0IHaPbtUiXHipp4bGqRPD/3lXr8/35wDC5fy1 AD8A== X-Gm-Message-State: ACrzQf0rQNsQt+SA6/+/Ut5POonf/L6FStXSSxZXvtYE5MTtogazbqMr 83AP6zlkdLqYEYP6y5dZCmva/aXpiYg= X-Google-Smtp-Source: AMsMyM6ZOiPbvkTvfTlenwkLoPJPMgEpp6fIyDcHVVVn9rvJuzmvX32HIUze3OK6yKdLpoU0Csn9Tw== X-Received: by 2002:a5d:64c4:0:b0:231:3d94:6eb2 with SMTP id f4-20020a5d64c4000000b002313d946eb2mr12294269wri.580.1666365232362; Fri, 21 Oct 2022 08:13:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id fc19-20020a05600c525300b003b505d26776sm3694737wmb.5.2022.10.21.08.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:51 -0700 (PDT) Message-Id: <3e2ea2a8b761fc525c7b9a32d1db3f0e00d7833c.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:37 +0000 Subject: [PATCH 7/9] subtree: process 'git-subtree-split' trailer in separate function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Both functions 'find_latest_squash' (called by 'git subtree merge --squash' and 'git subtree split --rejoin') and 'find_existing_splits' (called by git 'subtree split') loop through commits that have a 'git-subtree-dir' trailer, and then process the 'git-subtree-mainline' and 'git-subtree-split' trailers for those commits. The processing done for the 'git-subtree-split' trailer is simple: we check if the object exists with 'rev-parse' and set the variable 'sub' to the object name, or we die if the object does not exist. In a future commit we will add more steps to the processing of this trailer in order to make the code more robust. To reduce code duplication, move the processing of the 'git-subtree-split' trailer to a dedicated function, 'process_subtree_split_trailer'. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 2b3c429991b..b90ca0036f7 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -371,6 +371,15 @@ try_remove_previous () { fi } +# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH +process_subtree_split_trailer () { + assert test $# = 2 + b="$1" + sq="$2" + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || + die "fatal: could not rev-parse split hash $b from commit $sq" +} + # Usage: find_latest_squash DIR find_latest_squash () { assert test $# = 1 @@ -395,8 +404,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse --verify --quiet "$b^{commit}")" || - die "fatal: could not rev-parse split hash $b from commit $sq" + process_subtree_split_trailer "$b" "$sq" ;; END) if test -n "$sub" @@ -447,8 +455,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse --verify --quiet "$b^{commit}")" || - die "fatal: could not rev-parse split hash $b from commit $sq" + process_subtree_split_trailer "$b" "$sq" ;; END) debug "Main is: '$main'" From patchwork Fri Oct 21 15:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBC14C46467 for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiJUPOR (ORCPT ); Fri, 21 Oct 2022 11:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbiJUPN4 (ORCPT ); Fri, 21 Oct 2022 11:13:56 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E52110DE41 for ; Fri, 21 Oct 2022 08:13:55 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id a14so2478901wru.5 for ; Fri, 21 Oct 2022 08:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+5auV+87HwUM3VcadHiqwkdOm25yzEBwxRsUeNgr4Fc=; b=a1ocjvAsAUtDYK7UCTd1PJQUpCJvi+C7BTDfdvrejjVQr1WYR2cJRuN8439f2qx3Tt EPciYtlG2RwtLh7BhddNsqj8s/gc/nBXd3KAz6t1Yx7ksOEdghrk49Vm0QM+uDtVP0AG UX7ml7M7DZu9yoH20JEXWOB5riYqEcd9Ag7+3MPAnKOG96rJaVPCghklvzRL1CFtDAYg Q/4dhQJl8Kl1RUJ8rKakqH9j8/n1BHbqR8AK5Dzotq1mHFET5wSeEgY2hgWbasgdzUXj q2Rm0C0X7q8xnkeGPaTiv2P3eUn03I0+OFWHuB9z4PmkUyrUzwTC8PH7POz0Yr3VixDy iWrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+5auV+87HwUM3VcadHiqwkdOm25yzEBwxRsUeNgr4Fc=; b=7vRZ1uzywwKF5ZsLjZBPH570xziSVjW43Pb/YyMv9PCRyMHII+JExW1uXCdOLF1t8R t362NH3tJi01g3es7FRsRaipSWStm4az9bP6rkWWSEOPkTj2Vp8fhSdS3T090nH5ZMw8 sSkSAXqbTh1rA4zdQyV1iCy08PUt1nWd15Fw1ycsCOHK5a+BSE0/gDPQ90vJOUOE3SIt Xm+yTk5h1PB+Ku4rEIAqGZmcMsIHulaQqRB4K9ES38tepBRsVVHlgUX0juVncoqpdk2E 1ElOsn021/7f8f/2QlwajFkJEAaHMoahnyvnKFqsvhVeDJQ9lIw3D3TmhRjnyluv/LwM Sy9g== X-Gm-Message-State: ACrzQf0unqDCn0cUu645yHEe1pFKvDWIZ9SMw2SN/1q3uGhKZVA3M3Is qeMfTevxK3AzpzDZvpQTAJstd9XDR7k= X-Google-Smtp-Source: AMsMyM6LFZPZo+PTKw0+GXacYZs2f+9msSyxK6/exjXX5UfISuol/fi+6++5OmwIN9MmIUlZAbLJuQ== X-Received: by 2002:adf:cd0c:0:b0:22e:3434:e060 with SMTP id w12-20020adfcd0c000000b0022e3434e060mr12945074wrm.388.1666365233444; Fri, 21 Oct 2022 08:13:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h42-20020a05600c49aa00b003a5537bb2besm2663255wmp.25.2022.10.21.08.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:53 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:38 +0000 Subject: [PATCH 8/9] subtree: fix squash merging after annotated tag was squashed merged Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain When 'git subtree merge --squash $ref' is invoked, either directly or through 'git subtree pull --squash $repo $ref', the code looks for the latest squash merge of the subtree in order to create the new merge commit as a child of the previous squash merge. This search is done in function 'process_subtree_split_trailer', invoked by 'find_latest_squash', which looks for the most recent commit with a 'git-subtree-split' trailer; that trailer's value is the object name in the subtree repository of the ref that was last squash-merged. The function verifies that this object is present locally with 'git rev-parse', and aborts if it's not. The hash referenced by the 'git-subtree-split' trailer is guaranteed to correspond to a commit since it is the result of running 'git rev-parse -q --verify "$1^{commit}"' on the first argument of 'cmd_merge' (this corresponds to 'rev' in 'cmd_merge' which is passed through to 'new_squash_commit' and 'squash_msg'). But this is only the case since e4f8baa88a (subtree: parse revs in individual cmd_ functions, 2021-04-27), which went into Git 2.32. Before that commit, 'cmd_merge' verified the revision it was given using 'git rev-parse --revs-only "$@"'. Such an invocation, when fed the name of an annotated tag, would return the hash of the tag, not of the commit referenced by the tag. This leads to a failure in 'find_latest_squash' when squash-merging if the most recent squash-merge merged an annotated tag of the subtree repository, using a pre-2.32 version of 'git subtree', unless that previous annotated tag is present locally (which is not usually the case). We can fix this by fetching the object directly by its hash in 'process_subtree_split_trailer' when 'git rev-parse' fails, but in order to do so we need to know the name or URL of the subtree repository. This is not possible in general for 'git subtree merge', but is easy when it is invoked through 'git subtree pull' since in that case the subtree repository is passed by the user at the command line. Allow the 'git subtree pull' scenario to work out-of-the-box by adding an optional 'repository' argument to functions 'cmd_merge', 'find_latest_squash' and 'process_subtree_split_trailer', and invoke 'cmd_merge' with that 'repository' argument in 'cmd_pull'. If 'repository' is absent in 'process_subtree_split_trailer', instruct the user to try fetching the missing object directly. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 56 +++++++++++++++++++++++------- contrib/subtree/git-subtree.txt | 9 +++-- contrib/subtree/t/t7900-subtree.sh | 36 +++++++++++++++++++ 3 files changed, 86 insertions(+), 15 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index b90ca0036f7..2c67989fe8a 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -371,20 +371,45 @@ try_remove_previous () { fi } -# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH +# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY] process_subtree_split_trailer () { - assert test $# = 2 + assert test $# = 2 -o $# = 3 b="$1" sq="$2" - sub="$(git rev-parse --verify --quiet "$b^{commit}")" || - die "fatal: could not rev-parse split hash $b from commit $sq" + repository="" + if test "$#" = 3 + then + repository="$3" + fi + fail_msg="fatal: could not rev-parse split hash $b from commit $sq" + if ! sub="$(git rev-parse --verify --quiet "$b^{commit}")" + then + # if 'repository' was given, try to fetch the 'git-subtree-split' hash + # before 'rev-parse'-ing it again, as it might be a tag that we do not have locally + if test -n "${repository}" + then + git fetch "$repository" "$b" + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || + die "$fail_msg" + else + hint1=$(printf "hint: hash might be a tag, try fetching it from the subtree repository:") + hint2=$(printf "hint: git fetch $b") + fail_msg=$(printf "$fail_msg\n$hint1\n$hint2") + die "$fail_msg" + fi + fi } -# Usage: find_latest_squash DIR +# Usage: find_latest_squash DIR [REPOSITORY] find_latest_squash () { - assert test $# = 1 + assert test $# = 1 -o $# = 2 dir="$1" - debug "Looking for latest squash ($dir)..." + repository="" + if test "$#" = 2 + then + repository="$2" + fi + debug "Looking for latest squash (dir=$dir, repository=$repository)..." local indent=$(($indent + 1)) sq= @@ -404,7 +429,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - process_subtree_split_trailer "$b" "$sq" + process_subtree_split_trailer "$b" "$sq" "$repository" ;; END) if test -n "$sub" @@ -969,17 +994,22 @@ cmd_split () { exit 0 } -# Usage: cmd_merge REV +# Usage: cmd_merge REV [REPOSITORY] cmd_merge () { - test $# -eq 1 || - die "fatal: you must provide exactly one revision. Got: '$*'" + test $# -eq 1 -o $# -eq 2 || + die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'" rev=$(git rev-parse -q --verify "$1^{commit}") || die "fatal: '$1' does not refer to a commit" + repository="" + if test "$#" = 2 + then + repository="$2" + fi ensure_clean if test -n "$arg_addmerge_squash" then - first_split="$(find_latest_squash "$dir")" || exit $? + first_split="$(find_latest_squash "$dir" "$repository")" || exit $? if test -z "$first_split" then die "fatal: can't squash-merge: '$dir' was never added." @@ -1017,7 +1047,7 @@ cmd_pull () { ensure_clean ensure_valid_ref_format "$ref" git fetch "$repository" "$ref" || exit $? - cmd_merge FETCH_HEAD + cmd_merge FETCH_HEAD "$repository" } # Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 9cddfa26540..0e7524d7864 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git subtree' [] -P add 'git subtree' [] -P add -'git subtree' [] -P merge +'git subtree' [] -P merge [] 'git subtree' [] -P split [] [verse] @@ -76,7 +76,7 @@ add :: only a single commit from the subproject, rather than its entire history. -merge :: +merge []:: Merge recent changes up to into the subtree. As with normal 'git merge', this doesn't remove your own local changes; it just merges those @@ -88,6 +88,11 @@ If you use '--squash', the merge direction doesn't always have to be forward; you can use this command to go back in time from v2.5 to v2.4, for example. If your merge introduces a conflict, you can resolve it in the usual ways. ++ +When using '--squash', and the previous merge with '--squash' merged an +annotated tag of the subtree repository, that tag needs to be available locally. +If is given, a missing tag will automatically be fetched from that +repository. split []:: Extract a new, synthetic project history from the diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 249743ab9aa..d0671676c7a 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -43,6 +43,30 @@ last_commit_subject () { git log --pretty=format:%s -1 } +# Upon 'git subtree add|merge --squash' of an annotated tag, +# pre-2.32.0 versions of 'git subtree' would write the hash of the tag +# (sub1 below), instead of the commit (sub1^{commit}) in the +# "git-subtree-split" trailer. +# We immitate this behaviour below using a replace ref. +# This function creates 3 repositories: +# - $1 +# - $1-sub (added as subtree "sub" in $1) +# - $1-clone (clone of $1) +test_create_pre2_32_repo () { + subtree_test_create_repo "$1" && + subtree_test_create_repo "$1-sub" && + test_commit -C "$1" main1 && + test_commit -C "$1-sub" --annotate sub1 && + git -C "$1" subtree add --prefix="sub" --squash "../$1-sub" sub1 && + tag=$(git -C "$1" rev-parse FETCH_HEAD) && + commit=$(git -C "$1" rev-parse FETCH_HEAD^{commit}) && + git -C "$1" log -1 --format=%B HEAD^2 >msg && + test_commit -C "$1-sub" --annotate sub2 && + git clone --no-local "$1" "$1-clone" && + new_commit=$(cat msg | sed -e "s/$commit/$tag/" | git -C "$1-clone" commit-tree HEAD^2^{tree}) && + git -C "$1-clone" replace HEAD^2 $new_commit +} + test_expect_success 'shows short help text for -h' ' test_expect_code 129 git subtree -h >out 2>err && test_must_be_empty err && @@ -264,6 +288,13 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende ) ' +test_expect_success 'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' + test_create_pre2_32_repo "$test_count" && + git -C "$test_count-clone" fetch "../$test_count-sub" sub2 && + test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD && + git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub" +' + # # Tests for 'git subtree split' # @@ -630,6 +661,11 @@ test_expect_success 'pull rejects flags for split' ' ) ' +test_expect_success 'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' + test_create_pre2_32_repo "$test_count" && + git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2 +' + # # Tests for 'git subtree push' # From patchwork Fri Oct 21 15:13:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13014913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD1FC4167E for ; Fri, 21 Oct 2022 15:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230249AbiJUPOP (ORCPT ); Fri, 21 Oct 2022 11:14:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiJUPN5 (ORCPT ); Fri, 21 Oct 2022 11:13:57 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D722196ED1 for ; Fri, 21 Oct 2022 08:13:56 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id l16-20020a05600c4f1000b003c6c0d2a445so2174354wmq.4 for ; Fri, 21 Oct 2022 08:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=x1ckwiSuHx+BmDD4kVrquteOnAzUtDVZtmzpP+FfVv4=; b=Ev4q1BwebBj9GQpp7AvhrNWFnRlaD4vwdDr6fJeEs4Pib5xqdR8CTn6hU53/NK/8en nbt0K7rJFvnimVCH9Pku4rFCJB3dFZJ65ChQcOmEkhPSx0cCPcyn5Gbwo4UT1zNUu8Oj feEzEnBSc1W4w5+tV6S85fRuvsrHxgZxwFq0P5HCR9qZh3runxJwZNfHupwU3x9ClRRm VFqHJ4Dla4xlfU/Hre7xp0fg+ElrSnptD3Nf3WMcrYs0sk0fKN1j+rULoL0YRBYFbfN0 EAd2V1eavdZocUUklNRFJymRWYk4cCIS6QV8KAKd1wjC5qszyjeu6VrJLEQMBU6znnjm LB3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x1ckwiSuHx+BmDD4kVrquteOnAzUtDVZtmzpP+FfVv4=; b=a3MLQ6Smul/Y7VgUHXCaAZVcUhauZ6SmvBd5OdNyMBt2+/J1ybpCVuD5fOvW1tmnSw rQ/kNHf3cm++nLUptMg4hU+ffzZueEcrjjlL2ZbwpTtOtMN1ETL8bmWIIGTdpvKhCRVR mNsoAnmZ3DX8tZsQO/Vr4Vy+X+2KlZMQIwbOxQZEpSyxdMhq7k1v9BX/kRXdncY2+cVJ ohmVlHDDpIW1dSh7RSb7DOvTdYymkNPlMyAyGkeT3rScyT7T6tkJaaBMs3ztexvo3VaF LTwcUdmA9ja/mQ0QgvZuJ145YfV8J50u3v6Z12MXSJXl1Sa4eCRavZtWo1HV7ZoOm4bg pAJg== X-Gm-Message-State: ACrzQf2otqiUzEKl9uQ5vu4GfGe+1CVIUNAuCPuFD5IHvi/bcu8QujhM 9CxpqjgpFD4ZqXvSljLNHuGMjZhKKis= X-Google-Smtp-Source: AMsMyM7fSlHu6O7geEgvCFFzcKJ4aRH26svaRZhMM18JYxYherHx/cdS/S6eByM9Q+Qq1/zU5u1bFQ== X-Received: by 2002:a05:600c:5248:b0:3c6:faf9:3939 with SMTP id fc8-20020a05600c524800b003c6faf93939mr16104933wmb.100.1666365234618; Fri, 21 Oct 2022 08:13:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bs14-20020a056000070e00b00236545edc91sm1793349wrb.76.2022.10.21.08.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 08:13:54 -0700 (PDT) Message-Id: <86a842d50345f6d4d0b16c78d565474be6f8068a.1666365220.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 15:13:39 +0000 Subject: [PATCH 9/9] subtree: fix split after annotated tag was squashed merged Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Luke Shumaker , Thomas Koutcher , James Limbouris , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain The previous commit fixed a failure in 'git subtree merge --squash' when the previous squash-merge merged an annotated tag of the subtree repository which is missing locally. The same failure happens in 'git subtree split', either directly or when called by 'git subtree push', under the same circumstances: 'cmd_split' invokes 'find_existing_splits', which loops through previous commits and invokes 'git rev-parse' (via 'process_subtree_split_trailer') on the value of any 'git subtree-split' trailer it finds. This fails if this value is the hash of an annotated tag which is missing locally. Add a new optional argument 'repository' to 'cmd_split' and 'find_existing_splits', and invoke 'cmd_split' with that argument from 'cmd_push'. This allows 'process_subtree_split_trailer' to try to fetch the missing tag from the 'repository' if it's not available locally, mirroring the new behaviour of 'git subtree pull' and 'git subtree merge'. Signed-off-by: Philippe Blain --- contrib/subtree/git-subtree.sh | 26 ++++++++++++++++++-------- contrib/subtree/git-subtree.txt | 7 ++++++- contrib/subtree/t/t7900-subtree.sh | 12 ++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 2c67989fe8a..10c9c87839a 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -453,14 +453,19 @@ find_latest_squash () { done || exit $? } -# Usage: find_existing_splits DIR REV +# Usage: find_existing_splits DIR REV [REPOSITORY] find_existing_splits () { - assert test $# = 2 + assert test $# = 2 -o $# = 3 debug "Looking for prior splits..." local indent=$(($indent + 1)) dir="$1" rev="$2" + repository="" + if test "$#" = 3 + then + repository="$3" + fi main= sub= local grep_format="^git-subtree-dir: $dir/*\$" @@ -480,7 +485,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - process_subtree_split_trailer "$b" "$sq" + process_subtree_split_trailer "$b" "$sq" "$repository" ;; END) debug "Main is: '$main'" @@ -906,17 +911,22 @@ cmd_add_commit () { say >&2 "Added dir '$dir'" } -# Usage: cmd_split [REV] +# Usage: cmd_split [REV] [REPOSITORY] cmd_split () { if test $# -eq 0 then rev=$(git rev-parse HEAD) - elif test $# -eq 1 + elif test $# -eq 1 -o $# -eq 2 then rev=$(git rev-parse -q --verify "$1^{commit}") || die "fatal: '$1' does not refer to a commit" else - die "fatal: you must provide exactly one revision. Got: '$*'" + die "fatal: you must provide exactly one revision, and optionnally a repository. Got: '$*'" + fi + repository="" + if test "$#" = 2 + then + repository="$2" fi if test -n "$arg_split_rejoin" @@ -940,7 +950,7 @@ cmd_split () { done || exit $? fi - unrevs="$(find_existing_splits "$dir" "$rev")" || exit $? + unrevs="$(find_existing_splits "$dir" "$rev" "$repository")" || exit $? # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. @@ -1072,7 +1082,7 @@ cmd_push () { die "fatal: '$localrevname_presplit' does not refer to a commit" echo "git push using: " "$repository" "$refspec" - localrev=$(cmd_split "$localrev_presplit") || die + localrev=$(cmd_split "$localrev_presplit" "$repository") || die git push "$repository" "$localrev":"refs/heads/$remoteref" else die "fatal: '$dir' must already exist. Try 'git subtree add'." diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 0e7524d7864..004abf415b8 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -94,7 +94,7 @@ annotated tag of the subtree repository, that tag needs to be available locally. If is given, a missing tag will automatically be fetched from that repository. -split []:: +split [] []:: Extract a new, synthetic project history from the history of the subtree of , or of HEAD if no is given. The new history @@ -114,6 +114,11 @@ settings passed to 'split' (such as '--annotate') are the same. Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so 'git merge' and friends will work as expected. ++ +When a previous merge with '--squash' merged an annotated tag of the +subtree repository, that tag needs to be available locally. +If is given, a missing tag will automatically be fetched from that +repository. pull :: Exactly like 'merge', but parallels 'git pull' in that diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index d0671676c7a..341c169eca7 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -582,6 +582,12 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ) ' +test_expect_success 'split after annotated tag was added/merged with --squash pre-v2.32.0' ' + test_create_pre2_32_repo "$test_count" && + test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD && + git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub" +' + # # Tests for 'git subtree pull' # @@ -989,6 +995,12 @@ test_expect_success 'push "sub dir"/ with a local rev' ' ) ' +test_expect_success 'push after annotated tag was added/merged with --squash pre-v2.32.0' ' + test_create_pre2_32_repo "$test_count" && + test_create_commit "$test_count-clone" sub/main-sub1 && + git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline +' + # # Validity checking #