]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport-helper: fix sync issue on crashes
authorFelipe Contreras <felipe.contreras@gmail.com>
Sat, 12 Apr 2014 20:33:32 +0000 (15:33 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Apr 2014 21:03:33 +0000 (14:03 -0700)
When a remote helper crashes while pushing we should revert back to the
state before the push, however, it's possible that `git fast-export`
already finished its job, and therefore has exported the marks already.

This creates a synchronization problem because from that moment on
`git fast-{import,export}` will have marks that the remote helper is not
aware of and all further commands fail (if those marks are referenced).

The fix is to tell `git fast-export` to export to a temporary file, and
only after the remote helper has finishes successfully, move to the
final destination.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5801-remote-helpers.sh
transport-helper.c

index 25fd2e7f46cb559372125e08671445476cbf6022..aa3e223cde9cbc3c0e7575c834f1435f23620ada 100755 (executable)
@@ -220,6 +220,20 @@ test_expect_success 'push update refs failure' '
        )
 '
 
+clean_mark () {
+       cut -f 2 -d ' ' "$1" |
+       git cat-file --batch-check |
+       grep commit |
+       sort >$(basename "$1")
+}
+
+cmp_marks () {
+       test_when_finished "rm -rf git.marks testgit.marks" &&
+       clean_mark ".git/testgit/$1/git.marks" &&
+       clean_mark ".git/testgit/$1/testgit.marks" &&
+       test_cmp git.marks testgit.marks
+}
+
 test_expect_success 'proper failure checks for fetching' '
        (GIT_REMOTE_TESTGIT_FAILURE=1 &&
        export GIT_REMOTE_TESTGIT_FAILURE &&
@@ -232,7 +246,11 @@ test_expect_success 'proper failure checks for fetching' '
 
 test_expect_success 'proper failure checks for pushing' '
        (cd local &&
-       test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all
+       git checkout -b crash master &&
+       echo crash >>file &&
+       git commit -a -m crash &&
+       test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
+       cmp_marks origin
        )
 '
 
index c890db620bce7ea553e30a74e6f7a6b9d7226c13..b468e4f88e730f88a1d231a574585ace56e7066a 100644 (file)
@@ -435,7 +435,7 @@ static int get_exporter(struct transport *transport,
        fastexport->argv[argc++] = data->signed_tags ?
                "--signed-tags=verbatim" : "--signed-tags=warn-strip";
        if (data->export_marks) {
-               strbuf_addf(&tmp, "--export-marks=%s", data->export_marks);
+               strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
                fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
        }
        if (data->import_marks) {
@@ -911,7 +911,16 @@ static int push_refs_with_export(struct transport *transport,
 
        if (finish_command(&exporter))
                die("Error while running fast-export");
-       return push_update_refs_status(data, remote_refs, flags);
+       if (push_update_refs_status(data, remote_refs, flags))
+               return 1;
+
+       if (data->export_marks) {
+               strbuf_addf(&buf, "%s.tmp", data->export_marks);
+               rename(buf.buf, data->export_marks);
+               strbuf_release(&buf);
+       }
+
+       return 0;
 }
 
 static int push_refs(struct transport *transport,