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 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);
56 && !(flags & TRANSPORT_PUSH_ALL)
57 && remote->push_refspec_nr) {
58 refspec = remote->push_refspec;
59 refspec_nr = remote->push_refspec_nr;
62 for (i = 0; i < remote->url_nr; i++) {
63 struct transport *transport =
64 transport_get(remote, remote->url[i]);
67 transport_set_option(transport,
68 TRANS_OPT_RECEIVEPACK, receivepack);
70 transport_set_option(transport, TRANS_OPT_THIN, "yes");
73 fprintf(stderr, "Pushing to %s\n", remote->url[i]);
74 err = transport_push(transport, refspec_nr, refspec, flags);
75 err |= transport_disconnect(transport);
80 error("failed to push to '%s'", remote->url[i]);
86 int cmd_push(int argc, const char **argv, const char *prefix)
90 const char *repo = NULL; /* default repository */
92 for (i = 1; i < argc; i++) {
93 const char *arg = argv[i];
100 if (!strcmp(arg, "-v")) {
104 if (!prefixcmp(arg, "--repo=")) {
108 if (!strcmp(arg, "--all")) {
109 flags |= TRANSPORT_PUSH_ALL;
112 if (!strcmp(arg, "--dry-run")) {
113 flags |= TRANSPORT_PUSH_DRY_RUN;
116 if (!strcmp(arg, "--tags")) {
117 add_refspec("refs/tags/*");
120 if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) {
121 flags |= TRANSPORT_PUSH_FORCE;
124 if (!strcmp(arg, "--thin")) {
128 if (!strcmp(arg, "--no-thin")) {
132 if (!prefixcmp(arg, "--receive-pack=")) {
133 receivepack = arg + 15;
136 if (!prefixcmp(arg, "--exec=")) {
137 receivepack = arg + 7;
142 set_refspecs(argv + i, argc - i);
143 if ((flags & TRANSPORT_PUSH_ALL) && refspec)
146 return do_push(repo, flags);