Merge pull request #1512 from carlosmn/push-delete-only Fix push for delete-only and add travis rules to test it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/.travis.yml b/.travis.yml
index ad1172d..0d5746f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,6 +25,10 @@ install:
# Run the Build script
script:
+ - mkdir _temp
+ - git init --bare _temp/test.git
+ - git daemon --listen=localhost --export-all --enable=receive-pack --base-path=_temp _temp 2>/dev/null &
+ - export GITTEST_REMOTE_URL="git://localhost/test.git"
- mkdir _build
- cd _build
- cmake .. -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 9085198..a5ad1e4 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -807,13 +807,13 @@ int git_smart__push(git_transport *transport, git_push *push)
transport_smart *t = (transport_smart *)transport;
git_smart_subtransport_stream *s;
git_buf pktline = GIT_BUF_INIT;
- int error = -1;
+ int error = -1, need_pack = 0;
+ push_spec *spec;
+ unsigned int i;
#ifdef PUSH_DEBUG
{
git_remote_head *head;
- push_spec *spec;
- unsigned int i;
char hex[41]; hex[40] = '\0';
git_vector_foreach(&push->remote->refs, i, head) {
@@ -831,10 +831,23 @@ int git_smart__push(git_transport *transport, git_push *push)
}
#endif
+ /*
+ * Figure out if we need to send a packfile; which is in all
+ * cases except when we only send delete commands
+ */
+ git_vector_foreach(&push->specs, i, spec) {
+ if (spec->lref) {
+ need_pack = 1;
+ break;
+ }
+ }
+
if (git_smart__get_push_stream(t, &s) < 0 ||
gen_pktline(&pktline, push) < 0 ||
- s->write(s, git_buf_cstr(&pktline), git_buf_len(&pktline)) < 0 ||
- git_packbuilder_foreach(push->pb, &stream_thunk, s) < 0)
+ s->write(s, git_buf_cstr(&pktline), git_buf_len(&pktline)) < 0)
+ goto on_error;
+
+ if (need_pack && git_packbuilder_foreach(push->pb, &stream_thunk, s) < 0)
goto on_error;
/* If we sent nothing or the server doesn't support report-status, then