Skip to content

Commit 3994e64

Browse files
felipecgitster
authored andcommitted
transport-helper: fix sync issue on crashes
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 852e54b commit 3994e64

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

t/t5801-remote-helpers.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ test_expect_success 'push update refs failure' '
220220
)
221221
'
222222

223+
clean_mark () {
224+
cut -f 2 -d ' ' "$1" |
225+
git cat-file --batch-check |
226+
grep commit |
227+
sort >$(basename "$1")
228+
}
229+
230+
cmp_marks () {
231+
test_when_finished "rm -rf git.marks testgit.marks" &&
232+
clean_mark ".git/testgit/$1/git.marks" &&
233+
clean_mark ".git/testgit/$1/testgit.marks" &&
234+
test_cmp git.marks testgit.marks
235+
}
236+
223237
test_expect_success 'proper failure checks for fetching' '
224238
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
225239
export GIT_REMOTE_TESTGIT_FAILURE &&
@@ -232,7 +246,11 @@ test_expect_success 'proper failure checks for fetching' '
232246

233247
test_expect_success 'proper failure checks for pushing' '
234248
(cd local &&
235-
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all
249+
git checkout -b crash master &&
250+
echo crash >>file &&
251+
git commit -a -m crash &&
252+
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
253+
cmp_marks origin
236254
)
237255
'
238256

transport-helper.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int get_exporter(struct transport *transport,
435435
fastexport->argv[argc++] = data->signed_tags ?
436436
"--signed-tags=verbatim" : "--signed-tags=warn-strip";
437437
if (data->export_marks) {
438-
strbuf_addf(&tmp, "--export-marks=%s", data->export_marks);
438+
strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks);
439439
fastexport->argv[argc++] = strbuf_detach(&tmp, NULL);
440440
}
441441
if (data->import_marks) {
@@ -911,7 +911,16 @@ static int push_refs_with_export(struct transport *transport,
911911

912912
if (finish_command(&exporter))
913913
die("Error while running fast-export");
914-
return push_update_refs_status(data, remote_refs, flags);
914+
if (push_update_refs_status(data, remote_refs, flags))
915+
return 1;
916+
917+
if (data->export_marks) {
918+
strbuf_addf(&buf, "%s.tmp", data->export_marks);
919+
rename(buf.buf, data->export_marks);
920+
strbuf_release(&buf);
921+
}
922+
923+
return 0;
915924
}
916925

917926
static int push_refs(struct transport *transport,

0 commit comments

Comments
 (0)