6 #include "run-command.h"
11 static const char push_usage
[] = "git-push [--all] [--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
->uri_nr
; i
++) {
61 struct transport
*transport
=
62 transport_get(remote
, remote
->uri
[i
], 0);
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
->uri
[i
]);
72 err
= transport_push(transport
, refspec_nr
, refspec
, flags
);
73 err
|= transport_disconnect(transport
);
78 error("failed to push to '%s'", remote
->uri
[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
, "--tags")) {
111 add_refspec("refs/tags/*");
114 if (!strcmp(arg
, "--force") || !strcmp(arg
, "-f")) {
115 flags
|= TRANSPORT_PUSH_FORCE
;
118 if (!strcmp(arg
, "--thin")) {
122 if (!strcmp(arg
, "--no-thin")) {
126 if (!prefixcmp(arg
, "--receive-pack=")) {
127 receivepack
= arg
+ 15;
130 if (!prefixcmp(arg
, "--exec=")) {
131 receivepack
= arg
+ 7;
136 set_refspecs(argv
+ i
, argc
- i
);
140 return do_push(repo
, flags
);