From patchwork Tue Mar 14 01:53:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13173544 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 51B54C7618B for ; Tue, 14 Mar 2023 01:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230421AbjCNBxq (ORCPT ); Mon, 13 Mar 2023 21:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbjCNBxo (ORCPT ); Mon, 13 Mar 2023 21:53:44 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24E8A231E1 for ; Mon, 13 Mar 2023 18:53:42 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id i9so3968273wrp.3 for ; Mon, 13 Mar 2023 18:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678758820; 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=K/XfEhXKBkAFVnDlSJprYjSe5mimGStsOiyTu7d9d9w=; b=LsAHOczqaMej8urKTm+P3/EZLDlA6orA8tf0od3qiqvCu9Y+utb5NTf9UIeYqkns3F 4XkMV5drJBCGFgF/VkhRseuSOamM24RxwbmjQBveDtuB4wiGnhnPTYvSbmhF30YC/nOa f/A/e9YEnKytnyZtIWjVwCEk0SpfWv1sp2SH7DgDr6rLzySkTERqWLSAxkfAeGoAjkiF 2oHjh0ifd4FWo9YvmHX4Ygd1MSSl9WmMV3JQqNVcl1iHq1++JFn01prQ/gzY3XcldfiA 0bgZ6cU1W+GnPixHj4zg6Yc+84nGn9EGEU+GawTv8keYxJ9G4361j7hs1MyLIu7oKirf VGVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678758820; 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=K/XfEhXKBkAFVnDlSJprYjSe5mimGStsOiyTu7d9d9w=; b=LvFD6ec0274pIR2KOoalpbz8b3Jh9wpbDGGJwOFmgerE3YPC/0FbOJw9n7Np7fNmoo XQ8Rubtx9rP1W3W+AxExtG03d6QHOaidwPc+fE6EjB+qHy2yt2XrMTCYWiqfyVNrRFno zTHcJJH+jlROGEAFv87DHnD7AyHVDk7Aj3tYWtTRUaoFSnpKbOFI8WFsIhB4l+pRiBGc wjTQvqQ8bh8WU5KO7+dz49nKcFnBStDcDgX5dKmCZ38MErCEDs+Hb7tMQFYOBnKq9n+V JVfl3OZTWjQrus+rD3Y90P6lEeCAXwdrhpuxp+cjoQ90QL9PjoxfZMCNQQqbOqcUlzss jE2w== X-Gm-Message-State: AO0yUKX3jfzeB+grP9CdjYWTXd8rL2iZbFMBzSpMx8JSrAKceeE5BOVb sRf7WmlQxA44uSXAcgAHsT5VmP9Xyhw= X-Google-Smtp-Source: AK7set+dRWGHvrO0j3LbSFrj7QPf37QH4VBFQIWYozAgc8XypkDlWKQZb52SpMFsWoB7PXm/MdeI1w== X-Received: by 2002:adf:fa4e:0:b0:2c7:7b3:36c6 with SMTP id y14-20020adffa4e000000b002c707b336c6mr23602589wrr.52.1678758820324; Mon, 13 Mar 2023 18:53:40 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b10-20020a5d550a000000b002c706c754fesm803077wrv.32.2023.03.13.18.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 18:53:40 -0700 (PDT) Message-Id: <0fc704cf1c0724473a61086098d44c3a82938b03.1678758818.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 14 Mar 2023 01:53:37 +0000 Subject: [PATCH 1/2] diff: use HEAD for attributes when using bare repository Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: John Cai , John Cai Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: John Cai From: John Cai (a4cf900e diff: teach diff to read algorithm from diff driver, 2022-02-20) does not support bare repositories. Since running diff on bare repositories is often done on Git servers, it would be useful to allow bare repositories to also take advantage of setting the algorithm via the diff driver. Teach diff to check against the attributes from HEAD if a bare repository is being operated on. This change also allows custom diff drivers to work with bare repositories. Signed-off-by: John Cai Signed-off-by: Junio C Hamano --- Documentation/gitattributes.txt | 4 ++++ diff.c | 33 +++++++++++++++++++++++++++++---- t/lib-diff-alternative.sh | 10 ++++++++++ t/t4018-diff-funcname.sh | 11 +++++++++++ userdiff.c | 9 ++++++++- userdiff.h | 4 ++++ 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 39bfbca1ffe..15488bd92b2 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -758,6 +758,8 @@ with the above configuration, i.e. `j-c-diff`, with 7 parameters, just like `GIT_EXTERNAL_DIFF` program is called. See linkgit:git[1] for details. +When using a bare repository, the gitattributes from HEAD will be used. + Setting the internal diff algorithm ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -785,6 +787,8 @@ This diff algorithm applies to user facing diff output like git-diff(1), git-show(1) and is used for the `--stat` output as well. The merge machinery will not use the diff algorithm set through this method. +When using a bare repository, the gitattributes from HEAD will be used. + NOTE: If `diff..command` is defined for path with the `diff=` attribute, it is executed as an external diff driver (see above), and adding `diff..algorithm` has no effect, as the diff --git a/diff.c b/diff.c index 469e18aed20..51baf893bb0 100644 --- a/diff.c +++ b/diff.c @@ -29,6 +29,7 @@ #include "promisor-remote.h" #include "dir.h" #include "strmap.h" +#include "tree.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -4443,6 +4444,27 @@ static void fill_metainfo(struct strbuf *msg, } } +static void get_userdiff(struct diff_options *o, + struct userdiff_driver **drv, + const char *attr_path) +{ + const char *commit = "HEAD"; + struct object_id *tree_oid = NULL; + + if (is_bare_repository() && o->repo->gitdir) { + struct object_id oid; + + if (!get_oid(commit, &oid)) { + struct tree *t = parse_tree_indirect(&oid); + + if (t) + tree_oid = &t->object.oid; + } + } + + *drv = userdiff_find_by_tree_and_path(o->repo->index, tree_oid, attr_path); +} + static void run_diff_cmd(const char *pgm, const char *name, const char *other, @@ -4458,8 +4480,10 @@ static void run_diff_cmd(const char *pgm, int must_show_header = 0; struct userdiff_driver *drv = NULL; - if (o->flags.allow_external || !o->ignore_driver_algorithm) - drv = userdiff_find_by_path(o->repo->index, attr_path); + if (o->flags.allow_external || !o->ignore_driver_algorithm) { + + get_userdiff(o, &drv, attr_path); + } if (o->flags.allow_external && drv && drv->external) pgm = drv->external; @@ -4586,8 +4610,9 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o, const char *other; if (!o->ignore_driver_algorithm) { - struct userdiff_driver *drv = userdiff_find_by_path(o->repo->index, - p->one->path); + struct userdiff_driver *drv = NULL; + + get_userdiff(o, &drv, p->one->path); if (drv && drv->algorithm) set_diff_algorithm(o, drv->algorithm); diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh index a8f5d3274a5..0d99af83dd2 100644 --- a/t/lib-diff-alternative.sh +++ b/t/lib-diff-alternative.sh @@ -121,6 +121,16 @@ EOF test_cmp expect output ' + test_expect_success "$STRATEGY diff from attributes with bare repo" ' + echo "file* diff=driver" >.gitattributes && + git add file1 file2 .gitattributes && + git commit -m "adding files" && + git clone --bare --no-local . bare.git && + git -C bare.git config diff.driver.algorithm "$STRATEGY" && + git -C bare.git diff HEAD:file1 HEAD:file2 > output && + test_cmp expect output + ' + test_expect_success "$STRATEGY diff from attributes has valid diffstat" ' echo "file* diff=driver" >.gitattributes && git config diff.driver.algorithm "$STRATEGY" && diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 42a2b9a13b7..451af08c611 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -63,6 +63,17 @@ do test_i18ngrep ! fatal msg && test_i18ngrep ! error msg ' + test_expect_success "builtin $p pattern compiles on bare repo" ' + test_when_finished "rm -rf bare.git" && + echo "*.java diff=$p" >.gitattributes && + git add . && + git commit -am "adding files" && + git clone --bare --no-local . bare.git && + test_expect_code 1 git -C bare.git diff --exit-code \ + HEAD:A.java HEAD:B.java 2>msg && + test_i18ngrep ! fatal msg && + test_i18ngrep ! error msg + ' done test_expect_success 'last regexp must not be negated' ' diff --git a/userdiff.c b/userdiff.c index 58a3d59ef8f..2305d363244 100644 --- a/userdiff.c +++ b/userdiff.c @@ -408,6 +408,13 @@ struct userdiff_driver *userdiff_find_by_name(const char *name) struct userdiff_driver *userdiff_find_by_path(struct index_state *istate, const char *path) +{ + return userdiff_find_by_tree_and_path(istate, NULL, path); +} + +struct userdiff_driver *userdiff_find_by_tree_and_path(struct index_state *istate, + const struct object_id *tree_oid, + const char *path) { static struct attr_check *check; @@ -415,7 +422,7 @@ struct userdiff_driver *userdiff_find_by_path(struct index_state *istate, check = attr_check_initl("diff", NULL); if (!path) return NULL; - git_check_attr(istate, NULL, path, check); + git_check_attr(istate, tree_oid, path, check); if (ATTR_TRUE(check->items[0].value)) return &driver_true; diff --git a/userdiff.h b/userdiff.h index 24419db6973..f9cd7c238de 100644 --- a/userdiff.h +++ b/userdiff.h @@ -33,6 +33,10 @@ int userdiff_config(const char *k, const char *v); struct userdiff_driver *userdiff_find_by_name(const char *name); struct userdiff_driver *userdiff_find_by_path(struct index_state *istate, const char *path); +struct userdiff_driver *userdiff_find_by_tree_and_path(struct index_state *istate, + const struct object_id *tree_oid, + const char *path); + /* * Initialize any textconv-related fields in the driver and return it, or NULL From patchwork Tue Mar 14 01:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13173543 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 3F6A8C7618D for ; Tue, 14 Mar 2023 01:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbjCNBxs (ORCPT ); Mon, 13 Mar 2023 21:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjCNBxp (ORCPT ); Mon, 13 Mar 2023 21:53:45 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D655265C71 for ; Mon, 13 Mar 2023 18:53:42 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id k25-20020a7bc419000000b003ed23114fa7so3416413wmi.4 for ; Mon, 13 Mar 2023 18:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678758821; 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=XtwH0LqLFbMDIDH9+zvVsm9V2/wKnrXe+muFWgcRJiM=; b=cnwhVb3atAr0stdhsCWIsiIuM10sPnBmWbezseCXXV9BUbK6zFf9Cu2IWSXkDdkR3P OSzEciWDDHyVIoj+auotKEW0Fxh/E/mLhV3lGRgUC7SMdItAqCkg3z1CjKpuJpJsyNk3 Xu7MabeSlnr2uRVTmB//QHpnXZVTkLycp5UjLj/1KoMSpFf5XRqaJA+A4K4r1pPD2TYY o/ihWT9ElctdslFOlOb+GA2kXVBR6Fp2+1pJXLVhVZSDlASR9iW2WuO7Qp03gdzsXAZQ ANhDsvlxdVe861VJ7bwWganv5Hvl+HoJFMDfypKhVDYFCeFJSJuopvwxNwxzWS0srku0 bEvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678758821; 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=XtwH0LqLFbMDIDH9+zvVsm9V2/wKnrXe+muFWgcRJiM=; b=XTWNVcZWD/KSkbg5tR+G20N2UqPWIK0dqeT9rPOCiv0LNR8KIw15/IdTNJ22yCa1X1 IsrEcunYK/9hfusiIa2lbArL5bpXXx1TwGhgf6jcSx6qpJgfkJpo++WfGcYtjNyzQWnL zarzIcgt6Ihuu6pw97CI3T8rZb7Ux+MGaCVpRo87lJq6XKbJUf9qd74MlANeu1P0kJa7 Ng9Bbd96RmI8c73kfzDbBcONWm3FpMDsqImsh6EpukfRgQYHvg9dJVGBtE7TWgtlrri+ OdNDHq23F56sv3h1w31bZxE9ZoDao7K3rN1aGb9f+Bs5AIoqeUCx4SIUP4/scqQem3Wx uuwg== X-Gm-Message-State: AO0yUKXq4yWKje0bDLurlmejlyisAuot5/2xBCZoe+U/1k0yGx1n57sG y10BZIfeVTc2JsLMWHkTuPHT8RTqKp8= X-Google-Smtp-Source: AK7set8ESCRQloywmWLNUlI/Y+DNpijIKYuy74S5R1uG4BgvAXeaDxO1lFh7loAPSo5oFpAR4mGbyA== X-Received: by 2002:a05:600c:1f0f:b0:3df:ef18:b0a1 with SMTP id bd15-20020a05600c1f0f00b003dfef18b0a1mr13175624wmb.12.1678758821147; Mon, 13 Mar 2023 18:53:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w19-20020a1cf613000000b003e0015c8618sm1304685wmc.6.2023.03.13.18.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 18:53:40 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 14 Mar 2023 01:53:38 +0000 Subject: [PATCH 2/2] diff: add --attr-source to read gitattributes from a commit Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: John Cai , John Cai Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: John Cai From: John Cai The previous commit allows the diff machinery to read gitattributes from HEAD when a bare repository is being used. Some users may want to specify which commit to read gitattributes from. Teach diff a new --attr-source that can be used to pass in a commit. Signed-off-by: John Cai --- Documentation/diff-options.txt | 4 ++++ Documentation/gitattributes.txt | 8 ++++++-- diff.c | 16 ++++++++++----- diff.h | 1 + t/lib-diff-alternative.sh | 35 ++++++++++++++++++++++----------- t/t4018-diff-funcname.sh | 18 +++++++++++++++++ 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 7d73e976d99..d3a04937dde 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -173,6 +173,10 @@ endif::git-log[] --anchored=:: Generate a diff using the "anchored diff" algorithm. + +--attr-source=:: + Specify a commit to read gitattributes from when using a bare + repository when defining external drivers, or internal algorithms. + This option may be specified more than once. + diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 15488bd92b2..7f9451b56fa 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -758,7 +758,9 @@ with the above configuration, i.e. `j-c-diff`, with 7 parameters, just like `GIT_EXTERNAL_DIFF` program is called. See linkgit:git[1] for details. -When using a bare repository, the gitattributes from HEAD will be used. +When using a bare repository, the gitattributes from HEAD will be used, unless +the --attr-source option is used to specify a commit from which the +gitattributes will be read. Setting the internal diff algorithm ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -787,7 +789,9 @@ This diff algorithm applies to user facing diff output like git-diff(1), git-show(1) and is used for the `--stat` output as well. The merge machinery will not use the diff algorithm set through this method. -When using a bare repository, the gitattributes from HEAD will be used. +When using a bare repository, the gitattributes from HEAD will be used, unless +the --attr-source option is used to specify a commit from which the +gitattributes will be read. NOTE: If `diff..command` is defined for path with the `diff=` attribute, it is executed as an external diff driver diff --git a/diff.c b/diff.c index 51baf893bb0..e86cf33b7a9 100644 --- a/diff.c +++ b/diff.c @@ -4448,10 +4448,13 @@ static void get_userdiff(struct diff_options *o, struct userdiff_driver **drv, const char *attr_path) { - const char *commit = "HEAD"; + const char *commit = o->attr_source; struct object_id *tree_oid = NULL; - if (is_bare_repository() && o->repo->gitdir) { + if (!commit) + commit = "HEAD"; + + if ((o->attr_source || is_bare_repository()) && o->repo->gitdir) { struct object_id oid; if (!get_oid(commit, &oid)) { @@ -4459,6 +4462,8 @@ static void get_userdiff(struct diff_options *o, if (t) tree_oid = &t->object.oid; + } else if (o->attr_source) { + die(_("%s is not a valid object"), commit); } } @@ -4480,10 +4485,8 @@ static void run_diff_cmd(const char *pgm, int must_show_header = 0; struct userdiff_driver *drv = NULL; - if (o->flags.allow_external || !o->ignore_driver_algorithm) { - + if (o->flags.allow_external || !o->ignore_driver_algorithm) get_userdiff(o, &drv, attr_path); - } if (o->flags.allow_external && drv && drv->external) pgm = drv->external; @@ -5699,6 +5702,9 @@ struct option *add_diff_options(const struct option *opts, N_("disable all output of the program")), OPT_BOOL(0, "ext-diff", &options->flags.allow_external, N_("allow an external diff helper to be executed")), + OPT_STRING(0, "attr-source", &options->attr_source, + N_("attributes-source"), + N_("the commit to read attributes from")), OPT_CALLBACK_F(0, "textconv", options, NULL, N_("run external text conversion filters when comparing binary files"), PARSE_OPT_NOARG, diff_opt_textconv), diff --git a/diff.h b/diff.h index 8d770b1d579..59db40f66be 100644 --- a/diff.h +++ b/diff.h @@ -334,6 +334,7 @@ struct diff_options { const char *stat_sep; int xdl_opts; int ignore_driver_algorithm; + const char *attr_source; /* see Documentation/diff-options.txt */ char **anchors; diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh index 0d99af83dd2..a7cd4966749 100644 --- a/t/lib-diff-alternative.sh +++ b/t/lib-diff-alternative.sh @@ -112,25 +112,38 @@ EOF STRATEGY=$1 - test_expect_success "$STRATEGY diff from attributes" ' + test_expect_success "setup attributes files for tests with $STRATEGY" ' + git checkout -b master && echo "file* diff=driver" >.gitattributes && - git config diff.driver.algorithm "$STRATEGY" && - test_must_fail git diff --no-index file1 file2 > output && - cat expect && - cat output && + git add file1 file2 .gitattributes && + git commit -m "adding files" && + git checkout -b branchA && + echo "file* diff=driverA" >.gitattributes && + git add .gitattributes && + git commit -m "adding driverA as diff driver" && + git checkout master && + git clone --bare --no-local . bare.git + ' + + test_expect_success "$STRATEGY diff from attributes" ' + test_must_fail git -c diff.driver.algorithm=$STRATEGY diff --no-index file1 file2 > output && test_cmp expect output ' test_expect_success "$STRATEGY diff from attributes with bare repo" ' - echo "file* diff=driver" >.gitattributes && - git add file1 file2 .gitattributes && - git commit -m "adding files" && - git clone --bare --no-local . bare.git && - git -C bare.git config diff.driver.algorithm "$STRATEGY" && - git -C bare.git diff HEAD:file1 HEAD:file2 > output && + git -C bare.git -c diff.driver.algorithm=$STRATEGY diff HEAD:file1 HEAD:file2 >output && + test_cmp expect output + ' + + test_expect_success "diff from attributes with bare repo when branch different than HEAD" ' + git -C bare.git -c diff.driver.algorithm=myers -c diff.driverA.algorithm=$STRATEGY diff --attr-source branchA HEAD:file1 HEAD:file2 >output && test_cmp expect output ' + test_expect_success "diff from attributes with bare repo with invalid source" ' + test_must_fail git -C bare.git diff --attr-source invalid-branch HEAD:file1 HEAD:file2 + ' + test_expect_success "$STRATEGY diff from attributes has valid diffstat" ' echo "file* diff=driver" >.gitattributes && git config diff.driver.algorithm "$STRATEGY" && diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 451af08c611..30babcfae91 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -63,6 +63,7 @@ do test_i18ngrep ! fatal msg && test_i18ngrep ! error msg ' + test_expect_success "builtin $p pattern compiles on bare repo" ' test_when_finished "rm -rf bare.git" && echo "*.java diff=$p" >.gitattributes && @@ -74,6 +75,23 @@ do test_i18ngrep ! fatal msg && test_i18ngrep ! error msg ' + test_expect_success "builtin $p pattern compiles on bare repo with --attr-source" ' + test_when_finished "rm -rf bare.git" && + git checkout -B master && + echo "*.java diff=notexist" > .gitattributes && + git add .gitattributes && + git commit -am "changing gitattributes" && + git checkout -B branchA && + echo "*.java diff=$p" >.gitattributes && + git add .gitattributes && + git commit -am "changing gitattributes" && + git clone --bare --no-local . bare.git && + git -C bare.git symbolic-ref HEAD refs/heads/master && + test_expect_code 1 git -C bare.git diff --exit-code \ + --attr-source branchA HEAD:A.java HEAD:B.java 2>msg && + test_i18ngrep ! fatal msg && + test_i18ngrep ! error msg + ' done test_expect_success 'last regexp must not be negated' '