Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 142 lines (126 sloc) 2.938 kb
755225d git builtin "push"
Linus Torvalds authored
1 /*
2 * "git push"
3 */
4 #include "cache.h"
5 #include "refs.h"
6 #include "run-command.h"
7 #include "builtin.h"
5751f49 Move remote parsing into a library file out of builtin-push.
Daniel Barkalow authored
8 #include "remote.h"
9b28851 Push code for transport library
Daniel Barkalow authored
9 #include "transport.h"
755225d git builtin "push"
Linus Torvalds authored
10
d23842f rename --exec to --receive-pack for push and send-pack
Uwe Kleine-König authored
11 static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
755225d git builtin "push"
Linus Torvalds authored
12
9b28851 Push code for transport library
Daniel Barkalow authored
13 static int all, thin, verbose;
d23842f rename --exec to --receive-pack for push and send-pack
Uwe Kleine-König authored
14 static const char *receivepack;
755225d git builtin "push"
Linus Torvalds authored
15
96f1e58 remove unnecessary initializations
David Rientjes authored
16 static const char **refspec;
17 static int refspec_nr;
755225d git builtin "push"
Linus Torvalds authored
18
19 static void add_refspec(const char *ref)
20 {
21 int nr = refspec_nr + 1;
22 refspec = xrealloc(refspec, nr * sizeof(char *));
23 refspec[nr-1] = ref;
24 refspec_nr = nr;
25 }
26
27 static void set_refspecs(const char **refs, int nr)
28 {
8558fd9 Move refspec pattern matching to match_refs().
Daniel Barkalow authored
29 int i;
30 for (i = 0; i < nr; i++) {
31 const char *ref = refs[i];
32 if (!strcmp("tag", ref)) {
33 char *tag;
34 int len;
35 if (nr <= ++i)
36 die("tag shorthand without <tag>");
37 len = strlen(refs[i]) + 11;
38 tag = xmalloc(len);
39 strcpy(tag, "refs/tags/");
40 strcat(tag, refs[i]);
41 ref = tag;
411fb8b git-push: accept tag <tag> as advertised.
Junio C Hamano authored
42 }
8558fd9 Move refspec pattern matching to match_refs().
Daniel Barkalow authored
43 add_refspec(ref);
755225d git builtin "push"
Linus Torvalds authored
44 }
45 }
46
9b28851 Push code for transport library
Daniel Barkalow authored
47 static int do_push(const char *repo, int flags)
755225d git builtin "push"
Linus Torvalds authored
48 {
5751f49 Move remote parsing into a library file out of builtin-push.
Daniel Barkalow authored
49 int i, errs;
50 struct remote *remote = remote_get(repo);
755225d git builtin "push"
Linus Torvalds authored
51
5751f49 Move remote parsing into a library file out of builtin-push.
Daniel Barkalow authored
52 if (!remote)
755225d git builtin "push"
Linus Torvalds authored
53 die("bad repository '%s'", repo);
54
8558fd9 Move refspec pattern matching to match_refs().
Daniel Barkalow authored
55 if (!refspec && !all && remote->push_refspec_nr) {
56 refspec = remote->push_refspec;
57 refspec_nr = remote->push_refspec_nr;
5751f49 Move remote parsing into a library file out of builtin-push.
Daniel Barkalow authored
58 }
fd1d1b0 git-push to multiple locations does not stop at the first failure
Junio C Hamano authored
59 errs = 0;
28b91f8 @spearce Rename remote.uri to remote.url within remote handling internals
spearce authored
60 for (i = 0; i < remote->url_nr; i++) {
9b28851 Push code for transport library
Daniel Barkalow authored
61 struct transport *transport =
28b91f8 @spearce Rename remote.uri to remote.url within remote handling internals
spearce authored
62 transport_get(remote, remote->url[i]);
60b7f38 @MadCoder avoid to use error that shadows the function name, use err instead.
MadCoder authored
63 int err;
9b28851 Push code for transport library
Daniel Barkalow authored
64 if (receivepack)
65 transport_set_option(transport,
66 TRANS_OPT_RECEIVEPACK, receivepack);
67 if (thin)
68 transport_set_option(transport, TRANS_OPT_THIN, "yes");
69
bcc785f git push: add verbose flag and allow overriding of default target reposi...
Linus Torvalds authored
70 if (verbose)
28b91f8 @spearce Rename remote.uri to remote.url within remote handling internals
spearce authored
71 fprintf(stderr, "Pushing to %s\n", remote->url[i]);
9b28851 Push code for transport library
Daniel Barkalow authored
72 err = transport_push(transport, refspec_nr, refspec, flags);
73 err |= transport_disconnect(transport);
74
60b7f38 @MadCoder avoid to use error that shadows the function name, use err instead.
MadCoder authored
75 if (!err)
755225d git builtin "push"
Linus Torvalds authored
76 continue;
39878b0 git-push reports the URL after failing.
Junio C Hamano authored
77
28b91f8 @spearce Rename remote.uri to remote.url within remote handling internals
spearce authored
78 error("failed to push to '%s'", remote->url[i]);
fd1d1b0 git-push to multiple locations does not stop at the first failure
Junio C Hamano authored
79 errs++;
755225d git builtin "push"
Linus Torvalds authored
80 }
fd1d1b0 git-push to multiple locations does not stop at the first failure
Junio C Hamano authored
81 return !!errs;
755225d git builtin "push"
Linus Torvalds authored
82 }
83
a633fca Call setup_git_directory() much earlier
Linus Torvalds authored
84 int cmd_push(int argc, const char **argv, const char *prefix)
755225d git builtin "push"
Linus Torvalds authored
85 {
86 int i;
9b28851 Push code for transport library
Daniel Barkalow authored
87 int flags = 0;
5751f49 Move remote parsing into a library file out of builtin-push.
Daniel Barkalow authored
88 const char *repo = NULL; /* default repository */
755225d git builtin "push"
Linus Torvalds authored
89
90 for (i = 1; i < argc; i++) {
91 const char *arg = argv[i];
92
93 if (arg[0] != '-') {
94 repo = arg;
95 i++;
96 break;
97 }
bcc785f git push: add verbose flag and allow overriding of default target reposi...
Linus Torvalds authored
98 if (!strcmp(arg, "-v")) {
99 verbose=1;
100 continue;
101 }
cc44c76 Mechanical conversion to use prefixcmp()
Junio C Hamano authored
102 if (!prefixcmp(arg, "--repo=")) {
bcc785f git push: add verbose flag and allow overriding of default target reposi...
Linus Torvalds authored
103 repo = arg+7;
104 continue;
105 }
755225d git builtin "push"
Linus Torvalds authored
106 if (!strcmp(arg, "--all")) {
9b28851 Push code for transport library
Daniel Barkalow authored
107 flags |= TRANSPORT_PUSH_ALL;
755225d git builtin "push"
Linus Torvalds authored
108 continue;
109 }
110 if (!strcmp(arg, "--tags")) {
8558fd9 Move refspec pattern matching to match_refs().
Daniel Barkalow authored
111 add_refspec("refs/tags/*");
755225d git builtin "push"
Linus Torvalds authored
112 continue;
113 }
8f61549 @peff git-push: allow -f as an alias for --force
peff authored
114 if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) {
9b28851 Push code for transport library
Daniel Barkalow authored
115 flags |= TRANSPORT_PUSH_FORCE;
755225d git builtin "push"
Linus Torvalds authored
116 continue;
117 }
118 if (!strcmp(arg, "--thin")) {
119 thin = 1;
120 continue;
121 }
122 if (!strcmp(arg, "--no-thin")) {
123 thin = 0;
124 continue;
125 }
cc44c76 Mechanical conversion to use prefixcmp()
Junio C Hamano authored
126 if (!prefixcmp(arg, "--receive-pack=")) {
9b28851 Push code for transport library
Daniel Barkalow authored
127 receivepack = arg + 15;
d23842f rename --exec to --receive-pack for push and send-pack
Uwe Kleine-König authored
128 continue;
129 }
cc44c76 Mechanical conversion to use prefixcmp()
Junio C Hamano authored
130 if (!prefixcmp(arg, "--exec=")) {
9b28851 Push code for transport library
Daniel Barkalow authored
131 receivepack = arg + 7;
755225d git builtin "push"
Linus Torvalds authored
132 continue;
133 }
134 usage(push_usage);
135 }
136 set_refspecs(argv + i, argc - i);
8558fd9 Move refspec pattern matching to match_refs().
Daniel Barkalow authored
137 if (all && refspec)
138 usage(push_usage);
139
9b28851 Push code for transport library
Daniel Barkalow authored
140 return do_push(repo, flags);
755225d git builtin "push"
Linus Torvalds authored
141 }
Something went wrong with that request. Please try again.