{"thread":{"id":"9992","subject":"[PATCH] git-remote rm: add tests and minor fix-ups","startedAt":"2007-09-24T05:39:30Z","lastAt":"2007-09-24T05:39:30Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"53888","messageId":"7vsl54bp0t.fsf@gitster.siamese.dyndns.org","threadId":"9992","inReplyTo":null,"subject":"[PATCH] git-remote rm: add tests and minor fix-ups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-24T05:39:30Z","receivedAt":"2007-09-24T05:39:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This fixes \"git remote rm\" which always exited with a failure,\ncorrects indentation, and adds tests.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * People seemed to have liked \"git remote rm\"; additional tests\n   were requested to complete the series when the patch was\n   submitted but they never came, so I ended up doing the\n   janitorial work myself, which led to discovery of breakage in\n   the implementation.\n\n   Needless to say, I am not overly amused.\n\n git-remote.perl   |   10 ++---\n t/t5505-remote.sh |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 104 insertions(+), 6 deletions(-)\n create mode 100755 t/t5505-remote.sh\n\ndiff --git a/git-remote.perl b/git-remote.perl\nindex f513a8a..b7c1e01 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -317,7 +317,7 @@ sub update_remote {\n }\n \n sub rm_remote {\n-    my ($name) = @_;\n+\tmy ($name) = @_;\n \tif (!exists $remote->{$name}) {\n \t\tprint STDERR \"No such remote $name\\n\";\n \t\treturn;\n@@ -336,7 +336,7 @@ sub rm_remote {\n \t};\n \n \n-    my @refs = $git->command('for-each-ref',\n+\tmy @refs = $git->command('for-each-ref',\n \t\t'--format=%(refname) %(objectname)', \"refs/remotes/$name\");\n \tfor (@refs) {\n \t\t($ref, $object) = split;\n@@ -453,11 +453,9 @@ elsif ($ARGV[0] eq 'add') {\n elsif ($ARGV[0] eq 'rm') {\n \tif (@ARGV <= 1) {\n \t\tprint STDERR \"Usage: git remote rm <remote>\\n\";\n+\t\texit(1);\n \t}\n-    else {\n-        rm_remote($ARGV[1]);\n-\t}\n-    exit(1);\n+\trm_remote($ARGV[1]);\n }\n else {\n \tprint STDERR \"Usage: git remote\\n\";\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nnew file mode 100755\nindex 0000000..636aec2\n--- /dev/null\n+++ b/t/t5505-remote.sh\n@@ -0,0 +1,100 @@\n+#!/bin/sh\n+\n+test_description='git remote porcelain-ish'\n+\n+. ./test-lib.sh\n+\n+GIT_CONFIG=.git/config\n+export GIT_CONFIG\n+\n+setup_repository () {\n+\tmkdir \"$1\" && (\n+\tcd \"$1\" &&\n+\tgit init &&\n+\t>file &&\n+\tgit add file &&\n+\tgit commit -m \"Initial\" &&\n+\tgit checkout -b side &&\n+\t>elif &&\n+\tgit add elif &&\n+\tgit commit -m \"Second\" &&\n+\tgit checkout master\n+\t)\n+}\n+\n+tokens_match () {\n+\techo \"$1\" | tr ' ' '\\012' | sort | sed -e '/^$/d' >expect &&\n+\techo \"$2\" | tr ' ' '\\012' | sort | sed -e '/^$/d' >actual &&\n+\tdiff -u expect actual\n+}\n+\n+check_remote_track () {\n+\tactual=$(git remote show \"$1\" | sed -n -e '$p') &&\n+\tshift &&\n+\ttokens_match \"$*\" \"$actual\"\n+}\n+\n+check_tracking_branch () {\n+\tf=\"\" &&\n+\tr=$(git for-each-ref \"--format=%(refname)\" |\n+\t\tsed -ne \"s|^refs/remotes/$1/||p\") &&\n+\tshift &&\n+\ttokens_match \"$*\" \"$r\"\n+}\n+\n+test_expect_success setup '\n+\n+\tsetup_repository one &&\n+\tsetup_repository two &&\n+\t(\n+\t\tcd two && git branch another\n+\t) &&\n+\tgit clone one test\n+\n+'\n+\n+test_expect_success 'remote information for the origin' '\n+(\n+\tcd test &&\n+\ttokens_match origin \"$(git remote)\" &&\n+\tcheck_remote_track origin master side &&\n+\tcheck_tracking_branch origin HEAD master side\n+)\n+'\n+\n+test_expect_success 'add another remote' '\n+(\n+\tcd test &&\n+\tgit remote add -f second ../two &&\n+\ttokens_match \"origin second\" \"$(git remote)\" &&\n+\tcheck_remote_track origin master side &&\n+\tcheck_remote_track second master side another &&\n+\tcheck_tracking_branch second master side another &&\n+\tgit for-each-ref \"--format=%(refname)\" refs/remotes |\n+\tsed -e \"/^refs\\/remotes\\/origin\\//d\" \\\n+\t    -e \"/^refs\\/remotes\\/second\\//d\" >actual &&\n+\t>expect &&\n+\tdiff -u expect actual\n+)\n+'\n+\n+test_expect_success 'remove remote' '\n+(\n+\tcd test &&\n+\tgit remote rm second\n+)\n+'\n+\n+test_expect_success 'remove remote' '\n+(\n+\tcd test &&\n+\ttokens_match origin \"$(git remote)\" &&\n+\tcheck_remote_track origin master side &&\n+\tgit for-each-ref \"--format=%(refname)\" refs/remotes |\n+\tsed -e \"/^refs\\/remotes\\/origin\\//d\" >actual &&\n+\t>expect &&\n+\tdiff -u expect actual\n+)\n+'\n+\n+test_done\n-- \n1.5.3.2.1053.g5065\n"}]}