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... :)
threads / discuss / 13778
git remote rename, why dosen't it exists?
Subject: git remote rename, why dosen't it exists?
Re: git remote rename, why dosen't it exists?
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
Re: git remote rename, why dosen't it exists?
Hi,
On Tue, 3 Jun 2008, Matthieu Moy wrote:
Show 9 quoted lines
> 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
Re: git remote rename, why dosen't it exists?
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
Re: git remote rename, why dosen't it exists?
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:
Show 18 quoted lines
> 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 >
Re: git remote rename, why dosen't it exists?
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:
Show 18 quoted lines
> 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
Re: git remote rename, why dosen't it exists?
On Tue, 2008-06-03 at 21:12 +0100, Johannes Schindelin wrote:
Show 5 quoted lines
> 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. :-/
Show 28 quoted lines
> 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.
Re: git remote rename, why dosen't it exists?
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
Re: git remote rename, why dosen't it exists?
On Wed, 2008-06-04 at 16:51 +0100, Johannes Schindelin wrote:
Show 7 quoted lines
> 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?
Re: git remote rename, why dosen't it exists?
Hi,
On Wed, 4 Jun 2008, Victor Bogado da Silva Lins wrote:
Show 11 quoted lines
> 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
Re: git remote rename, why dosen't it exists?
Show 21 quoted lines
> 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