Merge branch 'pb/remote-mirror-config'
* pb/remote-mirror-config: Add a remote.*.mirror configuration option
This commit is contained in:
commit
dc484f2213
@ -921,6 +921,10 @@ remote.<name>.push::
|
|||||||
The default set of "refspec" for linkgit:git-push[1]. See
|
The default set of "refspec" for linkgit:git-push[1]. See
|
||||||
linkgit:git-push[1].
|
linkgit:git-push[1].
|
||||||
|
|
||||||
|
remote.<name>.mirror::
|
||||||
|
If true, pushing to this remote will automatically behave
|
||||||
|
as if the `\--mirror` option was given on the command line.
|
||||||
|
|
||||||
remote.<name>.skipDefaultUpdate::
|
remote.<name>.skipDefaultUpdate::
|
||||||
If true, this remote will be skipped by default when updating
|
If true, this remote will be skipped by default when updating
|
||||||
using the update subcommand of linkgit:git-remote[1].
|
using the update subcommand of linkgit:git-remote[1].
|
||||||
|
@ -70,7 +70,9 @@ the remote repository.
|
|||||||
be mirrored to the remote repository. Newly created local
|
be mirrored to the remote repository. Newly created local
|
||||||
refs will be pushed to the remote end, locally updated refs
|
refs will be pushed to the remote end, locally updated refs
|
||||||
will be force updated on the remote end, and deleted refs
|
will be force updated on the remote end, and deleted refs
|
||||||
will be removed from the remote end.
|
will be removed from the remote end. This is the default
|
||||||
|
if the configuration option `remote.<remote>.mirror` is
|
||||||
|
set.
|
||||||
|
|
||||||
\--dry-run::
|
\--dry-run::
|
||||||
Do everything except actually send the updates.
|
Do everything except actually send the updates.
|
||||||
|
@ -47,9 +47,11 @@ With `-m <master>` option, `$GIT_DIR/remotes/<name>/HEAD` is set
|
|||||||
up to point at remote's `<master>` branch instead of whatever
|
up to point at remote's `<master>` branch instead of whatever
|
||||||
branch the `HEAD` at the remote repository actually points at.
|
branch the `HEAD` at the remote repository actually points at.
|
||||||
+
|
+
|
||||||
In mirror mode, enabled with `--mirror`, the refs will not be stored
|
In mirror mode, enabled with `\--mirror`, the refs will not be stored
|
||||||
in the 'refs/remotes/' namespace, but in 'refs/heads/'. This option
|
in the 'refs/remotes/' namespace, but in 'refs/heads/'. This option
|
||||||
only makes sense in bare repositories.
|
only makes sense in bare repositories. If a remote uses mirror
|
||||||
|
mode, furthermore, `git push` will always behave as if `\--mirror`
|
||||||
|
was passed.
|
||||||
|
|
||||||
'rm'::
|
'rm'::
|
||||||
|
|
||||||
|
@ -56,6 +56,17 @@ static int do_push(const char *repo, int flags)
|
|||||||
if (!remote)
|
if (!remote)
|
||||||
die("bad repository '%s'", repo);
|
die("bad repository '%s'", repo);
|
||||||
|
|
||||||
|
if (remote->mirror)
|
||||||
|
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
|
||||||
|
|
||||||
|
if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) && refspec)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
|
||||||
|
(TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
|
||||||
|
return error("--all and --mirror are incompatible");
|
||||||
|
}
|
||||||
|
|
||||||
if (!refspec
|
if (!refspec
|
||||||
&& !(flags & TRANSPORT_PUSH_ALL)
|
&& !(flags & TRANSPORT_PUSH_ALL)
|
||||||
&& remote->push_refspec_nr) {
|
&& remote->push_refspec_nr) {
|
||||||
@ -95,6 +106,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
|
|||||||
int dry_run = 0;
|
int dry_run = 0;
|
||||||
int force = 0;
|
int force = 0;
|
||||||
int tags = 0;
|
int tags = 0;
|
||||||
|
int rc;
|
||||||
const char *repo = NULL; /* default repository */
|
const char *repo = NULL; /* default repository */
|
||||||
|
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
@ -130,14 +142,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
|
|||||||
repo = argv[0];
|
repo = argv[0];
|
||||||
set_refspecs(argv + 1, argc - 1);
|
set_refspecs(argv + 1, argc - 1);
|
||||||
}
|
}
|
||||||
if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) && refspec)
|
|
||||||
usage_with_options(push_usage, options);
|
|
||||||
|
|
||||||
if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
|
rc = do_push(repo, flags);
|
||||||
(TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
|
if (rc == -1)
|
||||||
error("--all and --mirror are incompatible");
|
|
||||||
usage_with_options(push_usage, options);
|
usage_with_options(push_usage, options);
|
||||||
}
|
else
|
||||||
|
return rc;
|
||||||
return do_push(repo, flags);
|
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,13 @@ static int add(int argc, const char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mirror) {
|
||||||
|
strbuf_reset(&buf);
|
||||||
|
strbuf_addf(&buf, "remote.%s.mirror", name);
|
||||||
|
if (git_config_set(buf.buf, "yes"))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (fetch && fetch_remote(name))
|
if (fetch && fetch_remote(name))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
53
remote.c
53
remote.c
@ -337,44 +337,49 @@ static int handle_config(const char *key, const char *value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
remote = make_remote(name, subkey - name);
|
remote = make_remote(name, subkey - name);
|
||||||
if (!value) {
|
if (!strcmp(subkey, ".mirror"))
|
||||||
/* if we ever have a boolean variable, e.g. "remote.*.disabled"
|
remote->mirror = git_config_bool(key, value);
|
||||||
* [remote "frotz"]
|
else if (!strcmp(subkey, ".skipdefaultupdate"))
|
||||||
* disabled
|
remote->skip_default_update = git_config_bool(key, value);
|
||||||
* is a valid way to set it to true; we get NULL in value so
|
|
||||||
* we need to handle it here.
|
else if (!strcmp(subkey, ".url")) {
|
||||||
*
|
const char *v;
|
||||||
* if (!strcmp(subkey, ".disabled")) {
|
if (git_config_string(&v, key, value))
|
||||||
* val = git_config_bool(key, value);
|
return -1;
|
||||||
* return 0;
|
add_url(remote, v);
|
||||||
* } else
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
return 0; /* ignore unknown booleans */
|
|
||||||
}
|
|
||||||
if (!strcmp(subkey, ".url")) {
|
|
||||||
add_url(remote, xstrdup(value));
|
|
||||||
} else if (!strcmp(subkey, ".push")) {
|
} else if (!strcmp(subkey, ".push")) {
|
||||||
add_push_refspec(remote, xstrdup(value));
|
const char *v;
|
||||||
|
if (git_config_string(&v, key, value))
|
||||||
|
return -1;
|
||||||
|
add_push_refspec(remote, v);
|
||||||
} else if (!strcmp(subkey, ".fetch")) {
|
} else if (!strcmp(subkey, ".fetch")) {
|
||||||
add_fetch_refspec(remote, xstrdup(value));
|
const char *v;
|
||||||
|
if (git_config_string(&v, key, value))
|
||||||
|
return -1;
|
||||||
|
add_fetch_refspec(remote, v);
|
||||||
} else if (!strcmp(subkey, ".receivepack")) {
|
} else if (!strcmp(subkey, ".receivepack")) {
|
||||||
|
const char *v;
|
||||||
|
if (git_config_string(&v, key, value))
|
||||||
|
return -1;
|
||||||
if (!remote->receivepack)
|
if (!remote->receivepack)
|
||||||
remote->receivepack = xstrdup(value);
|
remote->receivepack = v;
|
||||||
else
|
else
|
||||||
error("more than one receivepack given, using the first");
|
error("more than one receivepack given, using the first");
|
||||||
} else if (!strcmp(subkey, ".uploadpack")) {
|
} else if (!strcmp(subkey, ".uploadpack")) {
|
||||||
|
const char *v;
|
||||||
|
if (git_config_string(&v, key, value))
|
||||||
|
return -1;
|
||||||
if (!remote->uploadpack)
|
if (!remote->uploadpack)
|
||||||
remote->uploadpack = xstrdup(value);
|
remote->uploadpack = v;
|
||||||
else
|
else
|
||||||
error("more than one uploadpack given, using the first");
|
error("more than one uploadpack given, using the first");
|
||||||
} else if (!strcmp(subkey, ".tagopt")) {
|
} else if (!strcmp(subkey, ".tagopt")) {
|
||||||
if (!strcmp(value, "--no-tags"))
|
if (!strcmp(value, "--no-tags"))
|
||||||
remote->fetch_tags = -1;
|
remote->fetch_tags = -1;
|
||||||
} else if (!strcmp(subkey, ".proxy")) {
|
} else if (!strcmp(subkey, ".proxy")) {
|
||||||
remote->http_proxy = xstrdup(value);
|
return git_config_string((const char **)&remote->http_proxy,
|
||||||
} else if (!strcmp(subkey, ".skipdefaultupdate"))
|
key, value);
|
||||||
remote->skip_default_update = 1;
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
remote.h
1
remote.h
@ -26,6 +26,7 @@ struct remote {
|
|||||||
*/
|
*/
|
||||||
int fetch_tags;
|
int fetch_tags;
|
||||||
int skip_default_update;
|
int skip_default_update;
|
||||||
|
int mirror;
|
||||||
|
|
||||||
const char *receivepack;
|
const char *receivepack;
|
||||||
const char *uploadpack;
|
const char *uploadpack;
|
||||||
|
@ -25,7 +25,7 @@ mk_repo_pair () {
|
|||||||
(
|
(
|
||||||
cd master &&
|
cd master &&
|
||||||
git init &&
|
git init &&
|
||||||
git config remote.up.url ../mirror
|
git remote add $1 up ../mirror
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,4 +225,43 @@ test_expect_success 'push mirror adds, updates and removes tags together' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'remote.foo.mirror adds and removes branches' '
|
||||||
|
|
||||||
|
mk_repo_pair --mirror &&
|
||||||
|
(
|
||||||
|
cd master &&
|
||||||
|
echo one >foo && git add foo && git commit -m one &&
|
||||||
|
git branch keep master &&
|
||||||
|
git branch remove master &&
|
||||||
|
git push up &&
|
||||||
|
git branch -D remove
|
||||||
|
git push up
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
cd mirror &&
|
||||||
|
git show-ref -s --verify refs/heads/keep &&
|
||||||
|
invert git show-ref -s --verify refs/heads/remove
|
||||||
|
)
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'remote.foo.mirror=no has no effect' '
|
||||||
|
|
||||||
|
mk_repo_pair &&
|
||||||
|
(
|
||||||
|
cd master &&
|
||||||
|
echo one >foo && git add foo && git commit -m one &&
|
||||||
|
git config --add remote.up.mirror no &&
|
||||||
|
git branch keep master &&
|
||||||
|
git push --mirror up &&
|
||||||
|
git branch -D keep &&
|
||||||
|
git push up
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
cd mirror &&
|
||||||
|
git show-ref -s --verify refs/heads/keep
|
||||||
|
)
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user