Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>,
	"Stefan Beller" <stefanbeller@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jonathan Tan" <jonathantanmy@google.com>
Subject: Re: How do I "git fetch" with a custom <refspec> but a default remote?
Date: Sat, 14 Nov 2020 13:12:28 +0100
Message-ID: <87eekwf87n.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <877dqqhd3s.fsf@evledraar.gmail.com>


On Thu, Nov 12 2020, Ævar Arnfjörð Bjarmason wrote:

> On Wed, Nov 11 2020, Ævar Arnfjörð Bjarmason wrote:
>
>> In any case, this is one thing that came out of that
>> investigation. The code we're keeping by moving it to git-submodule.sh
>> can also be replaced by some C code we have, but I wanted to leave
>> that to another submission (if I'll get to it), and make this simply a
>> code removal.
>
> I may have missed a way to do $subject, but I don't think it's
> possible. The reason I want it is because git-submodule.sh does this:
>
>     git fetch $(get_default_remote) "$@" ;;
>
> Where that shellscript function gets the name of the remote configured
> for the current branch. If you do just a:
>
>     git fetch
>
> Then it will do the right thing, per its documentation:
>
>      When no remote is specified, by default the origin remote will be
>      used, unless there’s an upstream branch configured for the current
>      branch.
>
> But git-submodule.sh wants to do:
>
>     git fetch <default-remote> <some-sha1>
>
> So the caller is forced to find out what that is.
>
> I came up with this patch:
>     
>     diff --git a/builtin/fetch.c b/builtin/fetch.c
>     index f9c3c49f14..f110ac8d08 100644
>     --- a/builtin/fetch.c
>     +++ b/builtin/fetch.c
>     @@ -56,6 +56,7 @@ static int prune_tags = -1; /* unspecified */
>      #define PRUNE_TAGS_BY_DEFAULT 0 /* do we prune tags by default? */
>      
>      static int all, append, dry_run, force, keep, multiple, update_head_ok;
>     +static int default_remote;
>      static int write_fetch_head = 1;
>      static int verbosity, deepen_relative, set_upstream;
>      static int progress = -1;
>     @@ -140,6 +141,8 @@ static struct option builtin_fetch_options[] = {
>             OPT__VERBOSITY(&verbosity),
>             OPT_BOOL(0, "all", &all,
>                      N_("fetch from all remotes")),
>     +       OPT_BOOL(0, "default-remote", &default_remote,
>     +                N_("fetch from default remote")),
>             OPT_BOOL(0, "set-upstream", &set_upstream,
>                      N_("set upstream for git pull/fetch")),
>             OPT_BOOL('a', "append", &append,
>     @@ -1852,7 +1855,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
>                     else if (argc > 1)
>                             die(_("fetch --all does not make sense with refspecs"));
>                     (void) for_each_remote(get_one_remote_for_fetch, &list);
>     -       } else if (argc == 0) {
>     +       } else if (argc == 0 || default_remote) {
>                     /* No arguments -- use default remote */
>                     remote = remote_get(NULL);
>             } else if (multiple) {
>
> Which allows me to do:
>
>     -               git fetch $(get_default_remote) "$@" ;;
>     +               git fetch --default-remote "$@" ;;
>
>
> So it works, but what do we think about this calling convention? Do we
> have any prior art for commands that take positional arguments like
> <remote> and <refspec> where you'd like to use a default for an earlier
> argument to provide a subsequent one?
>
> To make it more general and consistent we'de probably like a --remote=*
> and --refspec arguments, so the invocation would be:
>
>     git fetch ([--remote=]<name> | --default-remote) [([--refspec=]<refspec> | --default-refspec)]
>
> But maybe I'm overthinking it...

To reply to my own question, this is possible with the --stdin option:

    echo <refpec> | git fetch --stdin

See 2b713c272c ("fetch: allow refspecs specified through stdin",
2020-08-17)[1].

1. https://lore.kernel.org/git/9f277f1631a37785dcd72a552dd86738d639ea59.1597722942.git.jonathantanmy@google.com/

  parent reply index

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-11 13:47 [PATCH 00/11] Start retiring .git/remotes/ and .git/branches/ for good Johannes Schindelin
2017-05-11 13:47 ` [PATCH 01/11] git-parse-remote: fix highly misleading man page Johannes Schindelin
2017-05-11 17:21   ` Stefan Beller
2017-05-11 19:14     ` Johannes Schindelin
2020-11-11 15:17     ` [PATCH 0/5] Remove now-unused git-parse-remote Ævar Arnfjörð Bjarmason
2020-11-11 17:37       ` Jeff King
2020-11-11 19:29         ` Junio C Hamano
2020-11-12 14:09         ` Ævar Arnfjörð Bjarmason
2020-11-12 18:42           ` Jeff King
2020-11-12 14:19       ` How do I "git fetch" with a custom <refspec> but a default remote? Ævar Arnfjörð Bjarmason
2020-11-12 18:51         ` Jeff King
2020-11-12 19:26           ` Chris Torek
2020-11-12 20:48             ` Jeff King
2020-11-12 21:22               ` Junio C Hamano
2020-11-14 12:12         ` Ævar Arnfjörð Bjarmason [this message]
2020-11-11 15:17     ` [PATCH 1/5] parse-remote: remove unused GIT_DIR variable Ævar Arnfjörð Bjarmason
2020-11-11 15:17     ` [PATCH 2/5] parse-remote: remove long-dead rebase code Ævar Arnfjörð Bjarmason
2020-11-11 15:17     ` [PATCH 3/5] parse-remote: remove long-dead git-pull.sh code Ævar Arnfjörð Bjarmason
2020-11-11 15:17     ` [PATCH 4/5] parse-remote: move used code to git-submodule.sh Ævar Arnfjörð Bjarmason
2020-11-11 15:17     ` [PATCH 5/5] parse-remote: remove this now-unused library Ævar Arnfjörð Bjarmason
2020-11-11 16:33       ` Junio C Hamano
2020-11-12 20:31         ` [PATCH v2 0/2] Retire git-parse-remote Junio C Hamano
2020-11-12 20:31           ` [PATCH v2 1/2] parse-remote: move used code to git-submodule.sh Junio C Hamano
2020-11-12 20:31           ` [PATCH v2 2/2] parse-remote: remove this now-unused library Junio C Hamano
2020-11-12 20:49           ` [PATCH v2 0/2] Retire git-parse-remote Jeff King
2020-11-12 21:25             ` Junio C Hamano
2020-11-13  9:42           ` Ævar Arnfjörð Bjarmason
2020-11-14 12:21           ` [PATCH v3 0/3] submodule sh->C & retire parse-remote Ævar Arnfjörð Bjarmason
2020-11-14 12:21           ` [PATCH v3 1/3] submodule: use "fetch" logic instead of custom remote discovery Ævar Arnfjörð Bjarmason
2020-11-16 21:13             ` Junio C Hamano
2020-11-14 12:21           ` [PATCH v3 2/3] submodule: remove sh function in favor of helper Ævar Arnfjörð Bjarmason
2020-11-14 12:21           ` [PATCH v3 3/3] parse-remote: remove this now-unused library Ævar Arnfjörð Bjarmason
2020-11-16 21:19             ` Junio C Hamano
2020-11-17 14:24               ` Ævar Arnfjörð Bjarmason
2017-05-11 13:47 ` [PATCH 02/11] Documentation: really deprecate .git/remotes/ and .git/branches/ Johannes Schindelin
2017-05-11 13:47 ` [PATCH 03/11] remote: warn loud and clear when .git/branches/ is *still* used Johannes Schindelin
2017-05-11 13:47 ` [PATCH 04/11] remote: warn loud and clear when .git/remotes/ " Johannes Schindelin
2017-05-11 13:47 ` [PATCH 05/11] Revert "Revert "Don't create the $GIT_DIR/branches directory on init"" Johannes Schindelin
2017-05-11 17:26   ` Stefan Beller
2017-05-11 13:47 ` [PATCH 06/11] PREVIEW: t5510: convert .git/remotes/ test to use a regular remote Johannes Schindelin
2017-05-11 13:47 ` [PATCH 07/11] PREVIEW: t5516: stop testing .git/branches/ functionality Johannes Schindelin
2017-05-11 13:47 ` [PATCH 08/11] PREVIEW: remote: remove support for migrating ancient remotes Johannes Schindelin
2017-05-11 13:48 ` [PATCH 09/11] PREVIEW: t5515: remove .git/remotes/ and .git/branches/ tests Johannes Schindelin
2017-05-11 13:48 ` [PATCH 10/11] PREVIEW: t0060: stop testing support for .git/remotes/ and .git/branches/ Johannes Schindelin
2017-05-11 13:48 ` [PATCH 11/11] PREVIEW: remove " Johannes Schindelin
2017-05-11 18:19   ` Stefan Beller
2017-05-11 19:19     ` Johannes Schindelin
2017-05-12  1:14 ` [PATCH 00/11] Start retiring .git/remotes/ and .git/branches/ for good Junio C Hamano
2017-05-12 10:18   ` Johannes Schindelin
2017-05-16  0:37     ` Junio C Hamano
2017-05-16  8:05       ` Ævar Arnfjörð Bjarmason
2017-05-16  9:06         ` Junio C Hamano
2017-05-16 10:02           ` Ævar Arnfjörð Bjarmason
2017-05-17  0:51             ` Junio C Hamano
2017-05-12 12:00   ` Junio C Hamano
2017-05-12 14:19     ` Johannes Schindelin
2017-05-12 17:38       ` Jonathan Nieder
2017-05-13 10:13         ` Junio C Hamano
2017-05-12 21:11       ` Junio C Hamano
2017-05-15  8:42         ` Johannes Schindelin
2017-05-12  9:11 ` Jeff King
2017-05-12 11:09   ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eekwf87n.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    --cc=stefanbeller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git