6 #include "run-command.h"
10 #include "transport.h"
13 static const char send_pack_usage
[] =
14 "git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
15 " --all and explicit <ref> specification are mutually exclusive.";
17 static struct send_pack_args args
;
19 static void print_helper_status(struct ref
*ref
)
21 struct strbuf buf
= STRBUF_INIT
;
23 for (; ref
; ref
= ref
->next
) {
24 const char *msg
= NULL
;
37 case REF_STATUS_UPTODATE
:
42 case REF_STATUS_REJECT_NONFASTFORWARD
:
44 msg
= "non-fast forward";
47 case REF_STATUS_REJECT_FETCH_FIRST
:
52 case REF_STATUS_REJECT_NEEDS_FORCE
:
57 case REF_STATUS_REJECT_ALREADY_EXISTS
:
59 msg
= "already exists";
62 case REF_STATUS_REJECT_NODELETE
:
63 case REF_STATUS_REMOTE_REJECT
:
67 case REF_STATUS_EXPECTING_REPORT
:
73 strbuf_addf(&buf
, "%s %s", res
, ref
->name
);
74 if (ref
->remote_status
)
75 msg
= ref
->remote_status
;
77 strbuf_addch(&buf
, ' ');
78 quote_two_c_style(&buf
, "", msg
, 0);
80 strbuf_addch(&buf
, '\n');
82 safe_write(1, buf
.buf
, buf
.len
);
87 int cmd_send_pack(int argc
, const char **argv
, const char *prefix
)
89 int i
, nr_refspecs
= 0;
90 const char **refspecs
= NULL
;
91 const char *remote_name
= NULL
;
92 struct remote
*remote
= NULL
;
93 const char *dest
= NULL
;
95 struct child_process
*conn
;
96 struct extra_have_objects extra_have
;
97 struct ref
*remote_refs
, *local_refs
;
99 int helper_status
= 0;
101 const char *receivepack
= "git-receive-pack";
103 unsigned int reject_reasons
;
107 for (i
= 1; i
< argc
; i
++, argv
++) {
108 const char *arg
= *argv
;
111 if (!prefixcmp(arg
, "--receive-pack=")) {
112 receivepack
= arg
+ 15;
115 if (!prefixcmp(arg
, "--exec=")) {
116 receivepack
= arg
+ 7;
119 if (!prefixcmp(arg
, "--remote=")) {
120 remote_name
= arg
+ 9;
123 if (!strcmp(arg
, "--all")) {
127 if (!strcmp(arg
, "--dry-run")) {
131 if (!strcmp(arg
, "--mirror")) {
132 args
.send_mirror
= 1;
135 if (!strcmp(arg
, "--force")) {
136 args
.force_update
= 1;
139 if (!strcmp(arg
, "--quiet")) {
143 if (!strcmp(arg
, "--verbose")) {
147 if (!strcmp(arg
, "--progress")) {
151 if (!strcmp(arg
, "--no-progress")) {
155 if (!strcmp(arg
, "--thin")) {
156 args
.use_thin_pack
= 1;
159 if (!strcmp(arg
, "--stateless-rpc")) {
160 args
.stateless_rpc
= 1;
163 if (!strcmp(arg
, "--helper-status")) {
167 usage(send_pack_usage
);
173 refspecs
= (const char **) argv
;
174 nr_refspecs
= argc
- i
;
178 usage(send_pack_usage
);
180 * --all and --mirror are incompatible; neither makes sense
183 if ((refspecs
&& (send_all
|| args
.send_mirror
)) ||
184 (send_all
&& args
.send_mirror
))
185 usage(send_pack_usage
);
188 remote
= remote_get(remote_name
);
189 if (!remote_has_url(remote
, dest
)) {
190 die("Destination %s is not a uri for %s",
196 progress
= !args
.quiet
&& isatty(2);
197 args
.progress
= progress
;
199 if (args
.stateless_rpc
) {
204 conn
= git_connect(fd
, dest
, receivepack
,
205 args
.verbose
? CONNECT_VERBOSE
: 0);
208 memset(&extra_have
, 0, sizeof(extra_have
));
210 get_remote_heads(fd
[0], &remote_refs
, REF_NORMAL
, &extra_have
);
212 transport_verify_remote_names(nr_refspecs
, refspecs
);
214 local_refs
= get_local_heads();
216 flags
= MATCH_REFS_NONE
;
219 flags
|= MATCH_REFS_ALL
;
220 if (args
.send_mirror
)
221 flags
|= MATCH_REFS_MIRROR
;
224 if (match_push_refs(local_refs
, &remote_refs
, nr_refspecs
, refspecs
, flags
))
227 set_ref_status_for_push(remote_refs
, args
.send_mirror
,
230 ret
= send_pack(&args
, fd
, conn
, remote_refs
, &extra_have
);
233 print_helper_status(remote_refs
);
238 ret
|= finish_connect(conn
);
241 transport_print_push_status(dest
, remote_refs
, args
.verbose
, 0, &reject_reasons
);
243 if (!args
.dry_run
&& remote
) {
245 for (ref
= remote_refs
; ref
; ref
= ref
->next
)
246 transport_update_tracking_ref(remote
, ref
, args
.verbose
);
249 if (!ret
&& !transport_refs_pushed(remote_refs
))
250 fprintf(stderr
, "Everything up-to-date\n");