6 #include "run-command.h"
11 #include "transport.h"
13 #include "sha1-array.h"
14 #include "gpg-interface.h"
16 static const char send_pack_usage[] =
17 "git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [--atomic] [<host>:]<directory> [<ref>...]\n"
18 " --all and explicit <ref> specification are mutually exclusive.";
20 static struct send_pack_args args;
22 static void print_helper_status(struct ref *ref)
24 struct strbuf buf = STRBUF_INIT;
26 for (; ref; ref = ref->next) {
27 const char *msg = NULL;
40 case REF_STATUS_UPTODATE:
45 case REF_STATUS_REJECT_NONFASTFORWARD:
47 msg = "non-fast forward";
50 case REF_STATUS_REJECT_FETCH_FIRST:
55 case REF_STATUS_REJECT_NEEDS_FORCE:
60 case REF_STATUS_REJECT_STALE:
65 case REF_STATUS_REJECT_ALREADY_EXISTS:
67 msg = "already exists";
70 case REF_STATUS_REJECT_NODELETE:
71 case REF_STATUS_REMOTE_REJECT:
75 case REF_STATUS_EXPECTING_REPORT:
81 strbuf_addf(&buf, "%s %s", res, ref->name);
82 if (ref->remote_status)
83 msg = ref->remote_status;
85 strbuf_addch(&buf, ' ');
86 quote_two_c_style(&buf, "", msg, 0);
88 strbuf_addch(&buf, '\n');
90 write_or_die(1, buf.buf, buf.len);
95 int cmd_send_pack(int argc, const char **argv, const char *prefix)
97 int i, nr_refspecs = 0;
98 const char **refspecs = NULL;
99 const char *remote_name = NULL;
100 struct remote *remote = NULL;
101 const char *dest = NULL;
103 struct child_process *conn;
104 struct sha1_array extra_have = SHA1_ARRAY_INIT;
105 struct sha1_array shallow = SHA1_ARRAY_INIT;
106 struct ref *remote_refs, *local_refs;
108 int helper_status = 0;
110 const char *receivepack = "git-receive-pack";
112 unsigned int reject_reasons;
115 struct push_cas_option cas = {0};
117 git_config(git_gpg_config, NULL);
120 for (i = 1; i < argc; i++, argv++) {
121 const char *arg = *argv;
124 if (starts_with(arg, "--receive-pack=")) {
125 receivepack = arg + 15;
128 if (starts_with(arg, "--exec=")) {
129 receivepack = arg + 7;
132 if (starts_with(arg, "--remote=")) {
133 remote_name = arg + 9;
136 if (!strcmp(arg, "--all")) {
140 if (!strcmp(arg, "--dry-run")) {
144 if (!strcmp(arg, "--mirror")) {
145 args.send_mirror = 1;
148 if (!strcmp(arg, "--force")) {
149 args.force_update = 1;
152 if (!strcmp(arg, "--quiet")) {
156 if (!strcmp(arg, "--verbose")) {
160 if (!strcmp(arg, "--signed")) {
164 if (!strcmp(arg, "--progress")) {
168 if (!strcmp(arg, "--no-progress")) {
172 if (!strcmp(arg, "--thin")) {
173 args.use_thin_pack = 1;
176 if (!strcmp(arg, "--atomic")) {
180 if (!strcmp(arg, "--stateless-rpc")) {
181 args.stateless_rpc = 1;
184 if (!strcmp(arg, "--stdin")) {
188 if (!strcmp(arg, "--helper-status")) {
192 if (!strcmp(arg, "--" CAS_OPT_NAME)) {
193 if (parse_push_cas_option(&cas, NULL, 0) < 0)
197 if (!strcmp(arg, "--no-" CAS_OPT_NAME)) {
198 if (parse_push_cas_option(&cas, NULL, 1) < 0)
202 if (starts_with(arg, "--" CAS_OPT_NAME "=")) {
203 if (parse_push_cas_option(&cas,
204 strchr(arg, '=') + 1, 0) < 0)
208 usage(send_pack_usage);
214 refspecs = (const char **) argv;
215 nr_refspecs = argc - i;
219 usage(send_pack_usage);
222 struct argv_array all_refspecs = ARGV_ARRAY_INIT;
224 for (i = 0; i < nr_refspecs; i++)
225 argv_array_push(&all_refspecs, refspecs[i]);
227 if (args.stateless_rpc) {
229 while ((buf = packet_read_line(0, NULL)))
230 argv_array_push(&all_refspecs, buf);
232 struct strbuf line = STRBUF_INIT;
233 while (strbuf_getline(&line, stdin, '\n') != EOF)
234 argv_array_push(&all_refspecs, line.buf);
235 strbuf_release(&line);
238 refspecs = all_refspecs.argv;
239 nr_refspecs = all_refspecs.argc;
243 * --all and --mirror are incompatible; neither makes sense
246 if ((refspecs && (send_all || args.send_mirror)) ||
247 (send_all && args.send_mirror))
248 usage(send_pack_usage);
251 remote = remote_get(remote_name);
252 if (!remote_has_url(remote, dest)) {
253 die("Destination %s is not a uri for %s",
259 progress = !args.quiet && isatty(2);
260 args.progress = progress;
262 if (args.stateless_rpc) {
267 conn = git_connect(fd, dest, receivepack,
268 args.verbose ? CONNECT_VERBOSE : 0);
271 get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL,
272 &extra_have, &shallow);
274 transport_verify_remote_names(nr_refspecs, refspecs);
276 local_refs = get_local_heads();
278 flags = MATCH_REFS_NONE;
281 flags |= MATCH_REFS_ALL;
282 if (args.send_mirror)
283 flags |= MATCH_REFS_MIRROR;
286 if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
289 if (!is_empty_cas(&cas))
290 apply_push_cas(&cas, remote, remote_refs);
292 set_ref_status_for_push(remote_refs, args.send_mirror,
295 ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
298 print_helper_status(remote_refs);
303 ret |= finish_connect(conn);
306 transport_print_push_status(dest, remote_refs, args.verbose, 0, &reject_reasons);
308 if (!args.dry_run && remote) {
310 for (ref = remote_refs; ref; ref = ref->next)
311 transport_update_tracking_ref(remote, ref, args.verbose);
314 if (!ret && !transport_refs_pushed(remote_refs))
315 fprintf(stderr, "Everything up-to-date\n");