# git remote rename, why dosen't it exists?

11 messages from 2008-06-03 to 2008-06-05. Participants: Victor Bogado da Silva Lins, Matthieu Moy, Johannes Schindelin, Vincent Kergonna.
Thread: https://gitlist.dev/t/13778

## Victor Bogado da Silva Lins, 2008-06-03 12:49

Subject: git remote rename, why dosen't it exists?
Message-ID: <1212497390.30731.3.camel@omicron.ep.petrobras.com.br>
URL: https://gitlist.dev/e/1212497390.30731.3.camel%40omicron.ep.petrobras.com.br

```
Well, that's about it, I need to rename my remotes. Mainly to move the
origin to another repository and I miss the feature. Since many time
there is a reason for a missing feature, I fought that maybe I should
ask here, before nosing around the sources... :)

```

## Matthieu Moy, 2008-06-03 13:27

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <vpq8wxmsl6q.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq8wxmsl6q.fsf%40bauges.imag.fr
In-Reply-To: <1212497390.30731.3.camel@omicron.ep.petrobras.com.br>

```
Victor Bogado da Silva Lins <victor@bogado.net> writes:

> Well, that's about it, I need to rename my remotes. Mainly to move the
> origin to another repository and I miss the feature. Since many time
> there is a reason for a missing feature, I fought that maybe I should
> ask here, before nosing around the sources... :)

I think editing .git/config to change the name of the remote would do
it.

-- 
Matthieu

```

## Johannes Schindelin, 2008-06-03 13:49

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <alpine.DEB.1.00.0806031449010.13507@racer.site.net>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806031449010.13507%40racer.site.net
In-Reply-To: <1212497390.30731.3.camel@omicron.ep.petrobras.com.br>

```
Hi,

On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:

> Well, that's about it, I need to rename my remotes. Mainly to move the 
> origin to another repository and I miss the feature. Since many time 
> there is a reason for a missing feature, I fought that maybe I should 
> ask here, before nosing around the sources... :)

The reason is easy to find: nobody cared enough about this feature to 
implement it.

Just tell me if you want to do it, I'll provide you with the necessary 
details.

Ciao,
Dscho

```

## Johannes Schindelin, 2008-06-03 13:52

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <alpine.DEB.1.00.0806031452450.13507@racer.site.net>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806031452450.13507%40racer.site.net
In-Reply-To: <vpq8wxmsl6q.fsf@bauges.imag.fr>

```
Hi,

On Tue, 3 Jun 2008, Matthieu Moy wrote:

> Victor Bogado da Silva Lins <victor@bogado.net> writes:
> 
> > Well, that's about it, I need to rename my remotes. Mainly to move the
> > origin to another repository and I miss the feature. Since many time
> > there is a reason for a missing feature, I fought that maybe I should
> > ask here, before nosing around the sources... :)
> 
> I think editing .git/config to change the name of the remote would do
> it.

No, that's not enough.

Ciao,
Dscho

```

## Victor Bogado da Silva Lins, 2008-06-03 14:34

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <1212503641.30731.11.camel@omicron.ep.petrobras.com.br>
URL: https://gitlist.dev/e/1212503641.30731.11.camel%40omicron.ep.petrobras.com.br
In-Reply-To: <alpine.DEB.1.00.0806031449010.13507@racer.site.net>

```
I don't mind trying. :P Pointers would help me, I already found that the
git-remote source is on the file builtin-remote.c, bu I have not yet
found the main function of it.

On Tue, 2008-06-03 at 14:49 +0100, Johannes Schindelin wrote:
> Hi,
> 
> On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:
> 
> > Well, that's about it, I need to rename my remotes. Mainly to move the 
> > origin to another repository and I miss the feature. Since many time 
> > there is a reason for a missing feature, I fought that maybe I should 
> > ask here, before nosing around the sources... :)
> 
> The reason is easy to find: nobody cared enough about this feature to 
> implement it.
> 
> Just tell me if you want to do it, I'll provide you with the necessary 
> details.
> 
> Ciao,
> Dscho
> 

```

## Johannes Schindelin, 2008-06-03 20:12

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <alpine.DEB.1.00.0806032102350.13507@racer.site.net>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806032102350.13507%40racer.site.net
In-Reply-To: <1212503641.30731.11.camel@omicron.ep.petrobras.com.br>

```
Hi,

[please do not top-post: it makes it very hard to follow the flow, 
especially on a high-volume mailing list like this.]

On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:

> On Tue, 2008-06-03 at 14:49 +0100, Johannes Schindelin wrote:
> 
> > On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:
> > 
> > > Well, that's about it, I need to rename my remotes. Mainly to move 
> > > the origin to another repository and I miss the feature. Since many 
> > > time there is a reason for a missing feature, I fought that maybe I 
> > > should ask here, before nosing around the sources... :)
> > 
> > The reason is easy to find: nobody cared enough about this feature to 
> > implement it.
> > 
> > Just tell me if you want to do it, I'll provide you with the necessary 
> > details.
>
> I don't mind trying. :P Pointers would help me, I already found that the
> git-remote source is on the file builtin-remote.c, bu I have not yet
> found the main function of it.

There is no main function, since it is a builtin.  The "main" function is 
called cmd_remote().

You might find inspiration with the rm() function, or might even be able 
to refactor the rm() function into an rm(), and an rm_or_rename() which
does both rm() and rename() depending on a second parameter being NULL or 
not.

Hth,
Dscho

```

## Victor Bogado da Silva Lins, 2008-06-04 14:54

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <1212591245.30731.17.camel@omicron.ep.petrobras.com.br>
URL: https://gitlist.dev/e/1212591245.30731.17.camel%40omicron.ep.petrobras.com.br
In-Reply-To: <alpine.DEB.1.00.0806032102350.13507@racer.site.net>

```
On Tue, 2008-06-03 at 21:12 +0100, Johannes Schindelin wrote:
> Hi,
> 
> [please do not top-post: it makes it very hard to follow the flow, 
> especially on a high-volume mailing list like this.]
> 
sorry about that. :-/ 

> On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:
> 
> > On Tue, 2008-06-03 at 14:49 +0100, Johannes Schindelin wrote:
> > 
> > > On Tue, 3 Jun 2008, Victor Bogado da Silva Lins wrote:
> > > 
> > > > Well, that's about it, I need to rename my remotes. Mainly to move 
> > > > the origin to another repository and I miss the feature. Since many 
> > > > time there is a reason for a missing feature, I fought that maybe I 
> > > > should ask here, before nosing around the sources... :)
> > > 
> > > The reason is easy to find: nobody cared enough about this feature to 
> > > implement it.
> > > 
> > > Just tell me if you want to do it, I'll provide you with the necessary 
> > > details.
> >
> > I don't mind trying. :P Pointers would help me, I already found that the
> > git-remote source is on the file builtin-remote.c, bu I have not yet
> > found the main function of it.
> 
> There is no main function, since it is a builtin.  The "main" function is 
> called cmd_remote().
> 
> You might find inspiration with the rm() function, or might even be able 
> to refactor the rm() function into an rm(), and an rm_or_rename() which
> does both rm() and rename() depending on a second parameter being NULL or 
> not.

I trying to refactor rm into rm_or_rename, but I stumbled into a
problem, how do I free a remote struct obtained with "remote_get"?
Another possibility would be another way to check if a remote already
exists without allocating it in case it does. The need comes from
testing whether the destination name already exists, if it does exists I
must free the remote_get and bail_out. 

```

## Johannes Schindelin, 2008-06-04 15:51

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <alpine.DEB.1.00.0806041649270.13507@racer.site.net>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806041649270.13507%40racer.site.net
In-Reply-To: <1212591245.30731.17.camel@omicron.ep.petrobras.com.br>

```
Hi,

On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:

> I trying to refactor [in builtin-remote.c] rm into rm_or_rename, but I 
> stumbled into a problem, how do I free a remote struct obtained with 
> "remote_get"?

At the moment, there is no way to do that.

> Another possibility would be another way to check if a remote already 
> exists without allocating it in case it does. The need comes from 
> testing whether the destination name already exists, if it does exists I 
> must free the remote_get and bail_out.

I think in the first step, you can just _not_ free() it, just die().

Ciao,
Dscho

```

## Victor Bogado da Silva Lins, 2008-06-05 02:53

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <1212634394.13109.10.camel@mithrandir.bogado.net>
URL: https://gitlist.dev/e/1212634394.13109.10.camel%40mithrandir.bogado.net
In-Reply-To: <alpine.DEB.1.00.0806041649270.13507@racer.site.net>

```
On Wed, 2008-06-04 at 16:51 +0100, Johannes Schindelin wrote:
> Hi,
> 
> On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:
> 
> > I trying to refactor [in builtin-remote.c] rm into rm_or_rename, but I 
> > stumbled into a problem, how do I free a remote struct obtained with 
> > "remote_get"?

It seems that git-remote thinks that remote_get will return NULL if
there is no such remote, but in fact it does not do this, it always
alloc a new remote struct and returns that newly allocated. This makes
the check useless. In fact that check always succeed, and if you feed a
non-existent remote name, the remote-rm will fail later when it tries to
remove a non-existent configuration.

The problem now is, how to reliably check if a remote exists or not. The
obvious exit is checking if the git configuration has the appropriated
key, but I was not able to find out how, the internal git api have no
documentation :P. Is there a simple way to check the existence of a key
in the git configuration? 

```

## Johannes Schindelin, 2008-06-05 04:30

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <alpine.DEB.1.00.0806050529350.21190@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806050529350.21190%40racer
In-Reply-To: <1212634394.13109.10.camel@mithrandir.bogado.net>

```
Hi,

On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:

> On Wed, 2008-06-04 at 16:51 +0100, Johannes Schindelin wrote:
>
> > On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:
> > 
> > > I trying to refactor [in builtin-remote.c] rm into rm_or_rename, but 
> > > I stumbled into a problem, how do I free a remote struct obtained 
> > > with "remote_get"?
> 
> It seems that git-remote thinks that remote_get will return NULL if
> there is no such remote, but in fact it does not do this, it always
> alloc a new remote struct and returns that newly allocated.

>From remote.c, remote_get(), line 601--602 in my checkout:

        if (!ret->url)
                return NULL;

Hth,
Dscho

```

## Vincent Kergonna, 2008-06-05 08:55

Subject: Re: git remote rename, why dosen't it exists?
Message-ID: <1666.78.153.224.34.1212656107.squirrel@mail.kergonna.fr>
URL: https://gitlist.dev/e/1666.78.153.224.34.1212656107.squirrel%40mail.kergonna.fr
In-Reply-To: <alpine.DEB.1.00.0806050529350.21190@racer>

```
> Hi,
>
> On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:
>
>> On Wed, 2008-06-04 at 16:51 +0100, Johannes Schindelin wrote:
>>
>> > On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:
>> >
>> > > I trying to refactor [in builtin-remote.c] rm into rm_or_rename, but
>> > > I stumbled into a problem, how do I free a remote struct obtained
>> > > with "remote_get"?
>>
>> It seems that git-remote thinks that remote_get will return NULL if
>> there is no such remote, but in fact it does not do this, it always
>> alloc a new remote struct and returns that newly allocated.
>
> From remote.c, remote_get(), line 601--602 in my checkout:
>
>         if (!ret->url)
>                 return NULL;
>

In fact, I think Victor is right. If you do a simple test (assuming you
don't have a remote named foo):

vincent:git$ git remote rm foo
error: Could not remove config section 'remote.foo'

You notice that it is trying to remove the configuration section for this
remote. We have hit the line 372 of builtin-remote.c:

if (git_config_rename_section(buf.buf, NULL) < 1)
    return error("Could not remove config section '%s'", buf.buf);

instead of exiting at line 364:

if (!remote)
    die("No such remote: %s", argv[1]);


-- 
Vincent

```
