6 #include "run-command.h"
11 static const char push_usage[] = "git-push [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
13 static int all, thin, verbose;
14 static const char *receivepack;
16 static const char **refspec;
17 static int refspec_nr;
19 static void add_refspec(const char *ref)
21 int nr = refspec_nr + 1;
22 refspec = xrealloc(refspec, nr * sizeof(char *));
27 static void set_refspecs(const char **refs, int nr)
30 for (i = 0; i < nr; i++) {
31 const char *ref = refs[i];
32 if (!strcmp("tag", ref)) {
36 die("tag shorthand without <tag>");
37 len = strlen(refs[i]) + 11;
39 strcpy(tag, "refs/tags/");
47 static int do_push(const char *repo, int flags)
50 struct remote *remote = remote_get(repo);
53 die("bad repository '%s'", repo);
55 if (!refspec && !all && remote->push_refspec_nr) {
56 refspec = remote->push_refspec;
57 refspec_nr = remote->push_refspec_nr;
60 for (i = 0; i < remote->url_nr; i++) {
61 struct transport *transport =
62 transport_get(remote, remote->url[i]);
65 transport_set_option(transport,
66 TRANS_OPT_RECEIVEPACK, receivepack);
68 transport_set_option(transport, TRANS_OPT_THIN, "yes");
71 fprintf(stderr, "Pushing to %s\n", remote->url[i]);
72 err = transport_push(transport, refspec_nr, refspec, flags);
73 err |= transport_disconnect(transport);
78 error("failed to push to '%s'", remote->url[i]);
84 int cmd_push(int argc, const char **argv, const char *prefix)
88 const char *repo = NULL; /* default repository */
90 for (i = 1; i < argc; i++) {
91 const char *arg = argv[i];
98 if (!strcmp(arg, "-v")) {
102 if (!prefixcmp(arg, "--repo=")) {
106 if (!strcmp(arg, "--all")) {
107 flags |= TRANSPORT_PUSH_ALL;
110 if (!strcmp(arg, "--dry-run")) {
111 flags |= TRANSPORT_PUSH_DRY_RUN;
114 if (!strcmp(arg, "--tags")) {
115 add_refspec("refs/tags/*");
118 if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) {
119 flags |= TRANSPORT_PUSH_FORCE;
122 if (!strcmp(arg, "--thin")) {
126 if (!strcmp(arg, "--no-thin")) {
130 if (!prefixcmp(arg, "--receive-pack=")) {
131 receivepack = arg + 15;
134 if (!prefixcmp(arg, "--exec=")) {
135 receivepack = arg + 7;
140 set_refspecs(argv + i, argc - i);
144 return do_push(repo, flags);