remote: add 'rm' subcommand
Introduce git-remote rm <name> which will: - Remove the remote config entry for <name>. - Remove any config entries for tracking branches of <name>. - Remove any stored remote branches of <name>. Signed-off-by: James Bowes <jbowes@dangerouslyinc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
James Bowes committed
Jun 5, 2007 at 19:25 UTC
611360443ef4d9e2f4def1e2c97727dd04e0d244
1 file changed
+38
git-remote.perl
+38
@@ -316,6 +316,34 @@ sub update_remote {
316
}
317
}
318
319
+sub rm_remote {
320
+ my ($name) = @_;
321
+ if (!exists $remote->{$name}) {
322
+ print STDERR "No such remote $name\n";
323
+ return;
324
+ }
325
+
326
+ $git->command('config', '--remove-section', "remote.$name");
327
+
328
+ eval {
329
+ my @trackers = $git->command('config', '--get-regexp',
330
+ 'branch.*.remote', $name);
331
+ for (@trackers) {
332
+ /^branch\.(.*)?\.remote/;
333
+ $git->config('--unset', "branch.$1.remote");
334
+ $git->config('--unset', "branch.$1.merge");
335
+ }
336
+ };
337
+
338
+
339
+ my @refs = $git->command('for-each-ref',
340
+ '--format=%(refname) %(objectname)', "refs/remotes/$name");
341
+ for (@refs) {
342
+ ($ref, $object) = split;
343
+ $git->command(qw(update-ref -d), $ref, $object);
344
+ }
345
+}
346
+
347
sub add_usage {
348
print STDERR "Usage: git remote add [-f] [-t track]* [-m master] <name> <url>\n";
349
exit(1);
@@ -422,9 +450,19 @@ elsif ($ARGV[0] eq 'add') {
450
}
451
add_remote($ARGV[1], $ARGV[2], \%opts);
452
}
453
+elsif ($ARGV[0] eq 'rm') {
454
+ if (@ARGV <= 1) {
455
+ print STDERR "Usage: git remote rm <remote>\n";
456
+ }
457
+ else {
458
+ rm_remote($ARGV[1]);
459
+ }
460
+ exit(1);
461
+}
462
else {
463
print STDERR "Usage: git remote\n";
464
print STDERR " git remote add <name> <url>\n";
465
+ print STDERR " git remote rm <name>\n";
466
print STDERR " git remote show <name>\n";
467
print STDERR " git remote prune <name>\n";
468
print STDERR " git remote update [group]\n";