threads / patch / 6875

patchTeach git-remote to update existing remotes by fetching from them

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

## tl;dr

8 messages between Feb 19, 2007 and Feb 20, 2007. Diffs are folded; open one to read it.

replies: 7people: 5as markdown or json

Theodore Ts'o· Feb 19, 2007, 04:00 UTC · lore

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(-)
Show changes to 3 files +26 −1

Documentation/config.txt, Documentation/git-remote.txt, git-remote.perl

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· Feb 19, 2007, 05:18 UTC · re: Theodore Ts'o · lore

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

"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· Feb 19, 2007, 07:32 UTC · re: Junio C Hamano · lore

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

Junio C Hamano <junkio@cox.net> wrote:
Show 6 quoted lines
> "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· Feb 19, 2007, 11:05 UTC · re: Shawn O. Pearce · lore

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

On 2/19/07, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 15 quoted lines
> 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 :)
Show 12 quoted lines
> 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").
Jakub Narebski· Feb 19, 2007, 13:21 UTC · re: Alex Riesen · lore

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

Alex Riesen wrote:
Show 57 quoted lines
> 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
Theodore Tso· Feb 19, 2007, 12:52 UTC · re: Shawn O. Pearce · lore

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

On Mon, Feb 19, 2007 at 02:32:38AM -0500, Shawn O. Pearce wrote:
Show 15 quoted lines
> <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
Junio C Hamano· Feb 19, 2007, 20:09 UTC · re: Theodore Tso · lore

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

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· Feb 20, 2007, 15:24 UTC · lore

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

Alex Riesen wrote:
Show 9 quoted lines
> 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

← back to recent threads