# [PATCH] Teach git-remote to update existing remotes by fetching from them

8 messages from 2007-02-19 to 2007-02-20. Participants: Theodore Ts'o, Junio C Hamano, Shawn O. Pearce, Alex Riesen, Theodore Tso, Jakub Narebski.
Thread: https://gitlist.dev/t/6875

## Theodore Ts'o, 2007-02-19 04:00

Subject: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <E1HIzh2-0001Ph-T2@candygram.thunk.org>
URL: https://gitlist.dev/e/E1HIzh2-0001Ph-T2%40candygram.thunk.org

```

This allows users to use the command "git remote update" to update all
remotes that are being tracked in the repository.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 Documentation/config.txt     |    4 ++++
 Documentation/git-remote.txt |   10 +++++++++-
 git-remote.perl              |   13 +++++++++++++
 3 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3865535..d8e696f 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -439,6 +439,10 @@ pull.octopus::
 pull.twohead::
 	The default merge strategy to use when pulling a single branch.
 
+remote.fetch::
+	The list of remotes which are fetched by "git remote update".
+	See gitlink:git-remote[1].
+
 remote.<name>.url::
 	The URL of a remote repository.  See gitlink:git-fetch[1] or
 	gitlink:git-push[1].
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index a60c31a..eed7aa2 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -13,6 +13,7 @@ SYNOPSIS
 'git-remote' add <name> <url>
 'git-remote' show <name>
 'git-remote' prune <name>
+'git-remote' update
 
 DESCRIPTION
 -----------
@@ -40,7 +41,14 @@ Gives some information about the remote <name>.
 
 Deletes all stale tracking branches under <name>.
 These stale branches have already been removed from the remote repository
-referenced by <name>, but are still locally available in "remotes/<name>".
+referenced by <name>, but are still locally available in
+"remotes/<name>".
+
+'update'::
+
+Fetch updates for the remotes in the repository.  By default all remotes
+are updated, but this can be configured via the configuration parameter 
+'remote.fetch'.   (See gitlink:git-config[1]).
 
 
 DISCUSSION
diff --git a/git-remote.perl b/git-remote.perl
index c56c5a8..1db9901 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -303,6 +303,18 @@ elsif ($ARGV[0] eq 'show') {
 		show_remote($ARGV[$i], $ls_remote);
 	}
 }
+elsif ($ARGV[0] eq 'update') {
+        my $conf = $git->config("remote.fetch");
+	if (defined($conf)) {
+	    	@remotes = split(' ', $conf);
+	} else {
+	        @remotes = sort keys %$remote;
+	}
+	for (@remotes) {
+		print "Fetching $_\n";
+		$git->command('fetch', "$_");
+	}
+}
 elsif ($ARGV[0] eq 'prune') {
 	my $ls_remote = 1;
 	my $i;
@@ -360,5 +372,6 @@ else {
 	print STDERR "       git remote add <name> <url>\n";
 	print STDERR "       git remote show <name>\n";
 	print STDERR "       git remote prune <name>\n";
+	print STDERR "       git remote update\n";
 	exit(1);
 }
-- 
1.5.0.50.gb75812-dirty

```

## Junio C Hamano, 2007-02-19 05:18

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <7virdybu9a.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7virdybu9a.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <E1HIzh2-0001Ph-T2@candygram.thunk.org>

```
"Theodore Ts'o" <tytso@mit.edu> writes:

> This allows users to use the command "git remote update" to update all
> remotes that are being tracked in the repository.

Sounds like a good idea.  Thanks.

```

## Shawn O. Pearce, 2007-02-19 07:32

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <20070219073238.GA30030@spearce.org>
URL: https://gitlist.dev/e/20070219073238.GA30030%40spearce.org
In-Reply-To: <7virdybu9a.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> wrote:
> "Theodore Ts'o" <tytso@mit.edu> writes:
> 
> > This allows users to use the command "git remote update" to update all
> > remotes that are being tracked in the repository.
> 
> Sounds like a good idea.  Thanks.

<personalwishlist>

It would be nice to define "gang remotes".  For example I want to
be able to have:

  `git fetch cs`  ==  `git fetch cs-one; git fetch cs-two`
  `git fetch jc`  ==  `git fetch origin; git fetch alt`

Why?  Well, I often have multiple remotes setup to the *same*
repository depending on the SSH hostname I want to use to access
that repository.  This has a lot to do with the way my firewalls
are setup and where I'm physically connected at any given time.

Yes, I really do have multiple remotes setup to the access the
same (remote) physical disk.  :)

Possible syntax:

	[remote "cs"]
		remote = cs-one
		remote = cs-two
	[remote "jc"]
		remote = origin
		remote = alt

</personalwishlist>

Obviously this is more work than Ted's nice little patch.  :)

-- 
Shawn.

```

## Alex Riesen, 2007-02-19 11:05

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <81b0412b0702190305j20cf2d10w8f75c4345ba0fc26@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0702190305j20cf2d10w8f75c4345ba0fc26%40mail.gmail.com
In-Reply-To: <20070219073238.GA30030@spearce.org>

```
On 2/19/07, Shawn O. Pearce <spearce@spearce.org> wrote:
> Junio C Hamano <junkio@cox.net> wrote:
> > "Theodore Ts'o" <tytso@mit.edu> writes:
> >
> > > This allows users to use the command "git remote update" to update all
> > > remotes that are being tracked in the repository.
> >
> > Sounds like a good idea.  Thanks.
>
> <personalwishlist>
>
> It would be nice to define "gang remotes".  For example I want to
> be able to have:
>
>   `git fetch cs`  ==  `git fetch cs-one; git fetch cs-two`
>   `git fetch jc`  ==  `git fetch origin; git fetch alt`

I was thinking about something very similar.

> Why?  Well, I often have multiple remotes setup to the *same*
> repository depending on the SSH hostname I want to use to access
> that repository.  This has a lot to do with the way my firewalls
> are setup and where I'm physically connected at any given time.

For all the same reasons :)

> Yes, I really do have multiple remotes setup to the access the
> same (remote) physical disk.  :)
>
> Possible syntax:
>
>         [remote "cs"]
>                 remote = cs-one
>                 remote = cs-two
>         [remote "jc"]
>                 remote = origin
>                 remote = alt
>

Or :

  [remote "jc"]
    url = git://...
    fetch = refs/heads/*:remotes/jc/*
    remote ("include"? "next"?) = origin

(I mean: it can be allowed to mix url/fetch and remote).

And:

  [remote "jc"]
    fail = all-fail
    remote = origin
    remote = backup

IOW: the fetch fails only if all fetches fail (with default
being "fail = first").

```

## Theodore Tso, 2007-02-19 12:52

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <20070219125219.GD25490@thunk.org>
URL: https://gitlist.dev/e/20070219125219.GD25490%40thunk.org
In-Reply-To: <20070219073238.GA30030@spearce.org>

```
On Mon, Feb 19, 2007 at 02:32:38AM -0500, Shawn O. Pearce wrote:
> <personalwishlist>
> 
> It would be nice to define "gang remotes".  For example I want to
> be able to have:
> 
>   `git fetch cs`  ==  `git fetch cs-one; git fetch cs-two`
>   `git fetch jc`  ==  `git fetch origin; git fetch alt`
> 
> Why?  Well, I often have multiple remotes setup to the *same*
> repository depending on the SSH hostname I want to use to access
> that repository.  This has a lot to do with the way my firewalls
> are setup and where I'm physically connected at any given time.
> 
> Yes, I really do have multiple remotes setup to the access the
> same (remote) physical disk.  :)

Here are a couple of things that I'm thinking about doing with the
patch I submitted yesterday:

1) Change the configuration parameter from remote.fetch to
remotes.default.update, and let "git remote update" take a parameter,
"git remote update <name>", where it will look up the list of remotes
to fetch via remotes.<name>.update, and default <name> to "default" if
it is not specified.

2) In the case of <name> == default, if remotes.default.update does
not exist, it will update all remotes, skipping remotes where
remote.*.no_default_fetch is true.  (This allows people who want to
omit certain special case remotes that only work if their connection
to the intranet is up, etc., to be able to set up something
convenientl; but for people who have more complex setups, they will
have to use the method specified in (1) above.

I thought about doing this via git-fetch, but (1) git-fetch.sh is
already way too complicated as it is, and I see that JC is in the
process of rewriting portions of it to C; by implementing in
git-remote.perl I avoided potential patch conflicts, and (2) fetching
groups of remotes would be overloading concepts for git-fetch, which
makes not only the implementation hard, but also the potential
semantics.  i.e., what does this mean?

[remote "cs"]
	remote = cs-one
	remote = cs-two
	url = git://git.kernel.org/pub/scm/git/git.git
	fetch = +refs/heads/*:refs/remotes/origin/*

						- Ted

```

## Jakub Narebski, 2007-02-19 13:21

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <erc846$bk7$1@sea.gmane.org>
URL: https://gitlist.dev/e/erc846%24bk7%241%40sea.gmane.org
In-Reply-To: <81b0412b0702190305j20cf2d10w8f75c4345ba0fc26@mail.gmail.com>

```
Alex Riesen wrote:

> On 2/19/07, Shawn O. Pearce <spearce@spearce.org> wrote:
>> Junio C Hamano <junkio@cox.net> wrote:
>> > "Theodore Ts'o" <tytso@mit.edu> writes:
>> >
>> > > This allows users to use the command "git remote update" to update all
>> > > remotes that are being tracked in the repository.
>> >
>> > Sounds like a good idea.  Thanks.
>>
>> <personalwishlist>
>>
>> It would be nice to define "gang remotes".  For example I want to
>> be able to have:
>>
>>   `git fetch cs`  ==  `git fetch cs-one; git fetch cs-two`
>>   `git fetch jc`  ==  `git fetch origin; git fetch alt`
> 
> I was thinking about something very similar.
> 
>> Why?  Well, I often have multiple remotes setup to the *same*
>> repository depending on the SSH hostname I want to use to access
>> that repository.  This has a lot to do with the way my firewalls
>> are setup and where I'm physically connected at any given time.
> 
> For all the same reasons :)
> 
>> Yes, I really do have multiple remotes setup to the access the
>> same (remote) physical disk.  :)
>>
>> Possible syntax:
>>
>>         [remote "cs"]
>>                 remote = cs-one
>>                 remote = cs-two
>>         [remote "jc"]
>>                 remote = origin
>>                 remote = alt
>>
> 
> Or :
> 
>   [remote "jc"]
>     url = git://...
>     fetch = refs/heads/*:remotes/jc/*
>     remote ("include"? "next"?) = origin
> 
> (I mean: it can be allowed to mix url/fetch and remote).
> 
> And:
> 
>   [remote "jc"]
>     fail = all-fail
>     remote = origin
>     remote = backup
> 
> IOW: the fetch fails only if all fetches fail (with default
> being "fail = first").

Or just allow fetch remotes to have multiple URLs, and fetch from all/try to fetch starting from first.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

```

## Junio C Hamano, 2007-02-19 20:09

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <7vfy917vu3.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vfy917vu3.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070219125219.GD25490@thunk.org>

```
Theodore Tso <tytso@mit.edu> writes:

> ..., and (2) fetching
> groups of remotes would be overloading concepts for git-fetch, which
> makes not only the implementation hard, but also the potential
> semantics.

I am with you 100% on this one.  Pushing to two separate places
makes perfect sense, but fetching (or worse, pulling) from two
separate places has certain "Huh?" factor in its semantics.

```

## Jakub Narebski, 2007-02-20 15:24

Subject: Re: [PATCH] Teach git-remote to update existing remotes by fetching from them
Message-ID: <200702201625.00841.jnareb@gmail.com>
URL: https://gitlist.dev/e/200702201625.00841.jnareb%40gmail.com
In-Reply-To: <20070219201111.GA3407@steel.home>

```
Alex Riesen wrote:
> Jakub Narebski, Mon, Feb 19, 2007 14:21:01 +0100:
>>> 
>>> IOW: the fetch fails only if all fetches fail (with default
>>> being "fail = first").
>> 
>> Or just allow fetch remotes to have multiple URLs, and fetch from
>> all/try to fetch starting from first. 
> 
> How do you define which refs to get from which url?

I was thinking about "mirror" situation, so all URL would be the same
repository, and the same refs. On fetch, try to fetch starting from 
first, on push, push to all.

-- 
Jakub Narebski
Poland

```
