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_ALREADY_EXISTS
:
60 msg
= "already exists";
63 case REF_STATUS_REJECT_NODELETE
:
64 case REF_STATUS_REMOTE_REJECT
:
68 case REF_STATUS_EXPECTING_REPORT
:
74 strbuf_addf(&buf
, "%s %s", res
, ref
->name
);
75 if (ref
->remote_status
)
76 msg
= ref
->remote_status
;
78 strbuf_addch(&buf
, ' ');
79 quote_two_c_style(&buf
, "", msg
, 0);
81 strbuf_addch(&buf
, '\n');
83 write_or_die(1, buf
.buf
, buf
.len
);
88 int cmd_send_pack(int argc
, const char **argv
, const char *prefix
)
90 int i
, nr_refspecs
= 0;
91 const char **refspecs
= NULL
;
92 const char *remote_name
= NULL
;
93 struct remote
*remote
= NULL
;
94 const char *dest
= NULL
;
96 struct child_process
*conn
;
97 struct extra_have_objects extra_have
;
98 struct ref
*remote_refs
, *local_refs
;
100 int helper_status
= 0;
102 const char *receivepack
= "git-receive-pack";
104 unsigned int reject_reasons
;
106 struct push_cas_option cas
= {0};
109 for (i
= 1; i
< argc
; i
++, argv
++) {
110 const char *arg
= *argv
;
113 if (!prefixcmp(arg
, "--receive-pack=")) {
114 receivepack
= arg
+ 15;
117 if (!prefixcmp(arg
, "--exec=")) {
118 receivepack
= arg
+ 7;
121 if (!prefixcmp(arg
, "--remote=")) {
122 remote_name
= arg
+ 9;
125 if (!strcmp(arg
, "--all")) {
129 if (!strcmp(arg
, "--dry-run")) {
133 if (!strcmp(arg
, "--mirror")) {
134 args
.send_mirror
= 1;
137 if (!strcmp(arg
, "--force")) {
138 args
.force_update
= 1;
141 if (!strcmp(arg
, "--quiet")) {
145 if (!strcmp(arg
, "--verbose")) {
149 if (!strcmp(arg
, "--progress")) {
153 if (!strcmp(arg
, "--no-progress")) {
157 if (!strcmp(arg
, "--thin")) {
158 args
.use_thin_pack
= 1;
161 if (!strcmp(arg
, "--stateless-rpc")) {
162 args
.stateless_rpc
= 1;
165 if (!strcmp(arg
, "--helper-status")) {
169 if (!strcmp(arg
, "--" CAS_OPT_NAME
)) {
170 if (parse_push_cas_option(&cas
, NULL
, 0) < 0)
174 if (!strcmp(arg
, "--no-" CAS_OPT_NAME
)) {
175 if (parse_push_cas_option(&cas
, NULL
, 1) < 0)
179 if (!prefixcmp(arg
, "--" CAS_OPT_NAME
"=")) {
180 if (parse_push_cas_option(&cas
,
181 strchr(arg
, '=') + 1, 1) < 0)
185 usage(send_pack_usage
);
191 refspecs
= (const char **) argv
;
192 nr_refspecs
= argc
- i
;
196 usage(send_pack_usage
);
198 * --all and --mirror are incompatible; neither makes sense
201 if ((refspecs
&& (send_all
|| args
.send_mirror
)) ||
202 (send_all
&& args
.send_mirror
))
203 usage(send_pack_usage
);
206 remote
= remote_get(remote_name
);
207 if (!remote_has_url(remote
, dest
)) {
208 die("Destination %s is not a uri for %s",
214 progress
= !args
.quiet
&& isatty(2);
215 args
.progress
= progress
;
217 if (args
.stateless_rpc
) {
222 conn
= git_connect(fd
, dest
, receivepack
,
223 args
.verbose
? CONNECT_VERBOSE
: 0);
226 memset(&extra_have
, 0, sizeof(extra_have
));
228 get_remote_heads(fd
[0], NULL
, 0, &remote_refs
, REF_NORMAL
, &extra_have
);
230 transport_verify_remote_names(nr_refspecs
, refspecs
);
232 local_refs
= get_local_heads();
234 flags
= MATCH_REFS_NONE
;
237 flags
|= MATCH_REFS_ALL
;
238 if (args
.send_mirror
)
239 flags
|= MATCH_REFS_MIRROR
;
242 if (match_push_refs(local_refs
, &remote_refs
, nr_refspecs
, refspecs
, flags
))
245 if (!is_empty_cas(&cas
))
246 apply_push_cas(&cas
, remote
, remote_refs
);
248 set_ref_status_for_push(remote_refs
, args
.send_mirror
,
251 ret
= send_pack(&args
, fd
, conn
, remote_refs
, &extra_have
);
254 print_helper_status(remote_refs
);
259 ret
|= finish_connect(conn
);
262 transport_print_push_status(dest
, remote_refs
, args
.verbose
, 0, &reject_reasons
);
264 if (!args
.dry_run
&& remote
) {
266 for (ref
= remote_refs
; ref
; ref
= ref
->next
)
267 transport_update_tracking_ref(remote
, ref
, args
.verbose
);
270 if (!ret
&& !transport_refs_pushed(remote_refs
))
271 fprintf(stderr
, "Everything up-to-date\n");