зеркало из https://github.com/microsoft/git.git
Merge branch 'ab/git-remote-exit-code'
Exit codes from "git remote add" etc. were not usable by scripted callers. * ab/git-remote-exit-code: remote: add meaningful exit code on missing/existing
This commit is contained in:
Коммит
ecf95d938b
|
@ -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
|
||||
--------
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
'
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче