summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-remote.txt11
-rw-r--r--builtin/remote.c42
-rwxr-xr-xt/t5505-remote.sh16
3 files changed, 47 insertions, 22 deletions
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index ea73386..31c29c9 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -203,6 +203,17 @@ The remote configuration is achieved using the `remote.origin.url` and
`remote.origin.fetch` configuration variables. (See
linkgit:git-config[1]).
+EXIT STATUS
+-----------
+
+On success, the exit status is `0`.
+
+When subcommands such as 'add', 'rename', and 'remove' can't find the
+remote in question, the exit status is `2`. When the remote already
+exists, the exit status is `3`.
+
+On any other error, the exit status may be any other non-zero value.
+
EXAMPLES
--------
diff --git a/builtin/remote.c b/builtin/remote.c
index 63f2b46..c1b211b 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -191,8 +191,10 @@ static int add(int argc, const char **argv)
url = argv[1];
remote = remote_get(name);
- if (remote_is_configured(remote, 1))
- die(_("remote %s already exists."), name);
+ if (remote_is_configured(remote, 1)) {
+ error(_("remote %s already exists."), name);
+ exit(3);
+ }
if (!valid_remote_name(name))
die(_("'%s' is not a valid remote name"), name);
@@ -685,15 +687,19 @@ static int mv(int argc, const char **argv)
rename.remote_branches = &remote_branches;
oldremote = remote_get(rename.old_name);
- if (!remote_is_configured(oldremote, 1))
- die(_("No such remote: '%s'"), rename.old_name);
+ if (!remote_is_configured(oldremote, 1)) {
+ error(_("No such remote: '%s'"), rename.old_name);
+ exit(2);
+ }
if (!strcmp(rename.old_name, rename.new_name) && oldremote->origin != REMOTE_CONFIG)
return migrate_file(oldremote);
newremote = remote_get(rename.new_name);
- if (remote_is_configured(newremote, 1))
- die(_("remote %s already exists."), rename.new_name);
+ if (remote_is_configured(newremote, 1)) {
+ error(_("remote %s already exists."), rename.new_name);
+ exit(3);
+ }
if (!valid_remote_name(rename.new_name))
die(_("'%s' is not a valid remote name"), rename.new_name);
@@ -826,8 +832,10 @@ static int rm(int argc, const char **argv)
usage_with_options(builtin_remote_rm_usage, options);
remote = remote_get(argv[1]);
- if (!remote_is_configured(remote, 1))
- die(_("No such remote: '%s'"), argv[1]);
+ if (!remote_is_configured(remote, 1)) {
+ error(_("No such remote: '%s'"), argv[1]);
+ exit(2);
+ }
known_remotes.to_delete = remote;
for_each_remote(add_known_remote, &known_remotes);
@@ -1508,8 +1516,10 @@ static int set_remote_branches(const char *remotename, const char **branches,
strbuf_addf(&key, "remote.%s.fetch", remotename);
remote = remote_get(remotename);
- if (!remote_is_configured(remote, 1))
- die(_("No such remote '%s'"), remotename);
+ if (!remote_is_configured(remote, 1)) {
+ error(_("No such remote '%s'"), remotename);
+ exit(2);
+ }
if (!add_mode && remove_all_fetch_refspecs(key.buf)) {
strbuf_release(&key);
@@ -1562,8 +1572,10 @@ static int get_url(int argc, const char **argv)
remotename = argv[0];
remote = remote_get(remotename);
- if (!remote_is_configured(remote, 1))
- die(_("No such remote '%s'"), remotename);
+ if (!remote_is_configured(remote, 1)) {
+ error(_("No such remote '%s'"), remotename);
+ exit(2);
+ }
url_nr = 0;
if (push_mode) {
@@ -1630,8 +1642,10 @@ static int set_url(int argc, const char **argv)
oldurl = newurl;
remote = remote_get(remotename);
- if (!remote_is_configured(remote, 1))
- die(_("No such remote '%s'"), remotename);
+ if (!remote_is_configured(remote, 1)) {
+ error(_("No such remote '%s'"), remotename);
+ exit(2);
+ }
if (push_mode) {
strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 4b0de6c..eaa6e90 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -145,8 +145,8 @@ test_expect_success 'remove remote protects local branches' '
test_expect_success 'remove errors out early when deleting non-existent branch' '
(
cd test &&
- echo "fatal: No such remote: '\''foo'\''" >expect &&
- test_must_fail git remote rm foo 2>actual &&
+ echo "error: No such remote: '\''foo'\''" >expect &&
+ test_expect_code 2 git remote rm foo 2>actual &&
test_i18ncmp expect actual
)
'
@@ -173,8 +173,8 @@ test_expect_success 'remove remote with a branch without configured merge' '
test_expect_success 'rename errors out early when deleting non-existent branch' '
(
cd test &&
- echo "fatal: No such remote: '\''foo'\''" >expect &&
- test_must_fail git remote rename foo bar 2>actual &&
+ echo "error: No such remote: '\''foo'\''" >expect &&
+ test_expect_code 2 git remote rename foo bar 2>actual &&
test_i18ncmp expect actual
)
'
@@ -188,16 +188,16 @@ test_expect_success 'rename errors out early when when new name is invalid' '
test_expect_success 'add existing foreign_vcs remote' '
test_config remote.foo.vcs bar &&
- echo "fatal: remote foo already exists." >expect &&
- test_must_fail git remote add foo bar 2>actual &&
+ echo "error: remote foo already exists." >expect &&
+ test_expect_code 3 git remote add foo bar 2>actual &&
test_i18ncmp expect actual
'
test_expect_success 'add existing foreign_vcs remote' '
test_config remote.foo.vcs bar &&
test_config remote.bar.vcs bar &&
- echo "fatal: remote bar already exists." >expect &&
- test_must_fail git remote rename foo bar 2>actual &&
+ echo "error: remote bar already exists." >expect &&
+ test_expect_code 3 git remote rename foo bar 2>actual &&
test_i18ncmp expect actual
'