6 #include "run-command.h"
11 #include "transport.h"
14 static const char send_pack_usage
[] =
15 "git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
16 " --all and explicit <ref> specification are mutually exclusive.";
18 static struct send_pack_args args
;
20 static void print_helper_status(struct ref
*ref
)
22 struct strbuf buf
= STRBUF_INIT
;
24 for (; ref
; ref
= ref
->next
) {
25 const char *msg
= NULL
;
38 case REF_STATUS_UPTODATE
:
43 case REF_STATUS_REJECT_NONFASTFORWARD
:
45 msg
= "non-fast forward";
48 case REF_STATUS_REJECT_FETCH_FIRST
:
53 case REF_STATUS_REJECT_NEEDS_FORCE
:
58 case REF_STATUS_REJECT_STALE
:
63 case REF_STATUS_REJECT_ALREADY_EXISTS
:
65 msg
= "already exists";
68 case REF_STATUS_REJECT_NODELETE
:
69 case REF_STATUS_REMOTE_REJECT
:
73 case REF_STATUS_EXPECTING_REPORT
:
79 strbuf_addf(&buf
, "%s %s", res
, ref
->name
);
80 if (ref
->remote_status
)
81 msg
= ref
->remote_status
;
83 strbuf_addch(&buf
, ' ');
84 quote_two_c_style(&buf
, "", msg
, 0);
86 strbuf_addch(&buf
, '\n');
88 write_or_die(1, buf
.buf
, buf
.len
);
93 int cmd_send_pack(int argc
, const char **argv
, const char *prefix
)
95 int i
, nr_refspecs
= 0;
96 const char **refspecs
= NULL
;
97 const char *remote_name
= NULL
;
98 struct remote
*remote
= NULL
;
99 const char *dest
= NULL
;
101 struct child_process
*conn
;
102 struct extra_have_objects extra_have
;
103 struct ref
*remote_refs
, *local_refs
;
105 int helper_status
= 0;
107 const char *receivepack
= "git-receive-pack";
109 unsigned int reject_reasons
;
111 struct push_cas_option cas
= {0};
114 for (i
= 1; i
< argc
; i
++, argv
++) {
115 const char *arg
= *argv
;
118 if (!prefixcmp(arg
, "--receive-pack=")) {
119 receivepack
= arg
+ 15;
122 if (!prefixcmp(arg
, "--exec=")) {
123 receivepack
= arg
+ 7;
126 if (!prefixcmp(arg
, "--remote=")) {
127 remote_name
= arg
+ 9;
130 if (!strcmp(arg
, "--all")) {
134 if (!strcmp(arg
, "--dry-run")) {
138 if (!strcmp(arg
, "--mirror")) {
139 args
.send_mirror
= 1;
142 if (!strcmp(arg
, "--force")) {
143 args
.force_update
= 1;
146 if (!strcmp(arg
, "--quiet")) {
150 if (!strcmp(arg
, "--verbose")) {
154 if (!strcmp(arg
, "--progress")) {
158 if (!strcmp(arg
, "--no-progress")) {
162 if (!strcmp(arg
, "--thin")) {
163 args
.use_thin_pack
= 1;
166 if (!strcmp(arg
, "--stateless-rpc")) {
167 args
.stateless_rpc
= 1;
170 if (!strcmp(arg
, "--helper-status")) {
174 if (!strcmp(arg
, "--" CAS_OPT_NAME
)) {
175 if (parse_push_cas_option(&cas
, NULL
, 0) < 0)
179 if (!strcmp(arg
, "--no-" CAS_OPT_NAME
)) {
180 if (parse_push_cas_option(&cas
, NULL
, 1) < 0)
184 if (!prefixcmp(arg
, "--" CAS_OPT_NAME
"=")) {
185 if (parse_push_cas_option(&cas
,
186 strchr(arg
, '=') + 1, 0) < 0)
190 usage(send_pack_usage
);
196 refspecs
= (const char **) argv
;
197 nr_refspecs
= argc
- i
;
201 usage(send_pack_usage
);
203 * --all and --mirror are incompatible; neither makes sense
206 if ((refspecs
&& (send_all
|| args
.send_mirror
)) ||
207 (send_all
&& args
.send_mirror
))
208 usage(send_pack_usage
);
211 remote
= remote_get(remote_name
);
212 if (!remote_has_url(remote
, dest
)) {
213 die("Destination %s is not a uri for %s",
219 progress
= !args
.quiet
&& isatty(2);
220 args
.progress
= progress
;
222 if (args
.stateless_rpc
) {
227 conn
= git_connect(fd
, dest
, receivepack
,
228 args
.verbose
? CONNECT_VERBOSE
: 0);
231 memset(&extra_have
, 0, sizeof(extra_have
));
233 get_remote_heads(fd
[0], NULL
, 0, &remote_refs
, REF_NORMAL
, &extra_have
);
235 transport_verify_remote_names(nr_refspecs
, refspecs
);
237 local_refs
= get_local_heads();
239 flags
= MATCH_REFS_NONE
;
242 flags
|= MATCH_REFS_ALL
;
243 if (args
.send_mirror
)
244 flags
|= MATCH_REFS_MIRROR
;
247 if (match_push_refs(local_refs
, &remote_refs
, nr_refspecs
, refspecs
, flags
))
250 if (!is_empty_cas(&cas
))
251 apply_push_cas(&cas
, remote
, remote_refs
);
253 set_ref_status_for_push(remote_refs
, args
.send_mirror
,
256 ret
= send_pack(&args
, fd
, conn
, remote_refs
, &extra_have
);
259 print_helper_status(remote_refs
);
264 ret
|= finish_connect(conn
);
267 transport_print_push_status(dest
, remote_refs
, args
.verbose
, 0, &reject_reasons
);
269 if (!args
.dry_run
&& remote
) {
271 for (ref
= remote_refs
; ref
; ref
= ref
->next
)
272 transport_update_tracking_ref(remote
, ref
, args
.verbose
);
275 if (!ret
&& !transport_refs_pushed(remote_refs
))
276 fprintf(stderr
, "Everything up-to-date\n");