@matheusbsbs / matheus-bagliano / commits / 683b56791b
Fork 0

git-remote rm: add tests and minor fix-ups

This fixes "git remote rm" which always exited with a failure, corrects indentation, and adds tests. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 23, 2007 at 22:29 UTC 683b56791b4e8a29ff9bc98c7faff69d7854d845
2 files changed +104 -6
git-remote.perl
+4 -6
@@ -317,7 +317,7 @@ sub update_remote {
317 }
318
319 sub rm_remote {
320 - my ($name) = @_;
320 + my ($name) = @_;
321 if (!exists $remote->{$name}) {
322 print STDERR "No such remote $name\n";
323 return;
@@ -336,7 +336,7 @@ sub rm_remote {
336 };
337
338
339 - my @refs = $git->command('for-each-ref',
339 + my @refs = $git->command('for-each-ref',
340 '--format=%(refname) %(objectname)', "refs/remotes/$name");
341 for (@refs) {
342 ($ref, $object) = split;
@@ -453,11 +453,9 @@ elsif ($ARGV[0] eq 'add') {
453 elsif ($ARGV[0] eq 'rm') {
454 if (@ARGV <= 1) {
455 print STDERR "Usage: git remote rm <remote>\n";
456 + exit(1);
457 }
457 - else {
458 - rm_remote($ARGV[1]);
459 - }
460 - exit(1);
458 + rm_remote($ARGV[1]);
459 }
460 else {
461 print STDERR "Usage: git remote\n";
t/t5505-remote.sh new
+100
@@ -0,0 +1,100 @@
1 +#!/bin/sh
2 +
3 +test_description='git remote porcelain-ish'
4 +
5 +. ./test-lib.sh
6 +
7 +GIT_CONFIG=.git/config
8 +export GIT_CONFIG
9 +
10 +setup_repository () {
11 + mkdir "$1" && (
12 + cd "$1" &&
13 + git init &&
14 + >file &&
15 + git add file &&
16 + git commit -m "Initial" &&
17 + git checkout -b side &&
18 + >elif &&
19 + git add elif &&
20 + git commit -m "Second" &&
21 + git checkout master
22 + )
23 +}
24 +
25 +tokens_match () {
26 + echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
27 + echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
28 + diff -u expect actual
29 +}
30 +
31 +check_remote_track () {
32 + actual=$(git remote show "$1" | sed -n -e '$p') &&
33 + shift &&
34 + tokens_match "$*" "$actual"
35 +}
36 +
37 +check_tracking_branch () {
38 + f="" &&
39 + r=$(git for-each-ref "--format=%(refname)" |
40 + sed -ne "s|^refs/remotes/$1/||p") &&
41 + shift &&
42 + tokens_match "$*" "$r"
43 +}
44 +
45 +test_expect_success setup '
46 +
47 + setup_repository one &&
48 + setup_repository two &&
49 + (
50 + cd two && git branch another
51 + ) &&
52 + git clone one test
53 +
54 +'
55 +
56 +test_expect_success 'remote information for the origin' '
57 +(
58 + cd test &&
59 + tokens_match origin "$(git remote)" &&
60 + check_remote_track origin master side &&
61 + check_tracking_branch origin HEAD master side
62 +)
63 +'
64 +
65 +test_expect_success 'add another remote' '
66 +(
67 + cd test &&
68 + git remote add -f second ../two &&
69 + tokens_match "origin second" "$(git remote)" &&
70 + check_remote_track origin master side &&
71 + check_remote_track second master side another &&
72 + check_tracking_branch second master side another &&
73 + git for-each-ref "--format=%(refname)" refs/remotes |
74 + sed -e "/^refs\/remotes\/origin\//d" \
75 + -e "/^refs\/remotes\/second\//d" >actual &&
76 + >expect &&
77 + diff -u expect actual
78 +)
79 +'
80 +
81 +test_expect_success 'remove remote' '
82 +(
83 + cd test &&
84 + git remote rm second
85 +)
86 +'
87 +
88 +test_expect_success 'remove remote' '
89 +(
90 + cd test &&
91 + tokens_match origin "$(git remote)" &&
92 + check_remote_track origin master side &&
93 + git for-each-ref "--format=%(refname)" refs/remotes |
94 + sed -e "/^refs\/remotes\/origin\//d" >actual &&
95 + >expect &&
96 + diff -u expect actual
97 +)
98 +'
99 +
100 +test_done