Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 4eb97ef

Browse files
committed
Merge pull request libgit2#2756 from libgit2/cmn/push-error-concerns
Fold `git_push_unpack_ok()` into `git_push_finish()`
2 parents cd305c2 + 85a6d5f commit 4eb97ef

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ v0.21 + 1
8888
* Rename git_remote_load() to git_remote_lookup() to bring it in line
8989
with the rest of the lookup functions.
9090

91+
* git_push_unpack_ok() has been removed and git_push_finish() now
92+
returns an error if the unpacking failed.
93+
9194
* Introduce git_merge_bases() and the git_oidarray type to expose all
9295
merge bases between two commits.
9396

include/git2/push.h

+7-14
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,21 @@ GIT_EXTERN(int) git_push_update_tips(
128128
const char *reflog_message);
129129

130130
/**
131-
* Actually push all given refspecs
131+
* Perform the push
132132
*
133-
* Note: To check if the push was successful (i.e. all remote references
134-
* have been updated as requested), you need to call both
135-
* `git_push_unpack_ok` and `git_push_status_foreach`. The remote
136-
* repository might have refused to update some or all of the references.
133+
* This function will return an error in case of a protocol error or
134+
* the server being unable to unpack the data we sent.
135+
*
136+
* The return value does not reflect whether the server accepted or
137+
* refused any reference updates. Use `git_push_status_foreach()` in
138+
* order to find out which updates were accepted or rejected.
137139
*
138140
* @param push The push object
139141
*
140142
* @return 0 or an error code
141143
*/
142144
GIT_EXTERN(int) git_push_finish(git_push *push);
143145

144-
/**
145-
* Check if remote side successfully unpacked
146-
*
147-
* @param push The push object
148-
*
149-
* @return true if remote side successfully unpacked, false otherwise
150-
*/
151-
GIT_EXTERN(int) git_push_unpack_ok(const git_push *push);
152-
153146
/**
154147
* Invoke callback `cb' on each status entry
155148
*

src/push.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,12 @@ int git_push_finish(git_push *push)
632632
(error = do_push(push)) < 0)
633633
return error;
634634

635-
return 0;
636-
}
635+
if (!push->unpack_ok) {
636+
error = -1;
637+
giterr_set(GITERR_NET, "unpacking the sent packfile failed on the remote");
638+
}
637639

638-
int git_push_unpack_ok(const git_push *push)
639-
{
640-
return push->unpack_ok;
640+
return error;
641641
}
642642

643643
int git_push_status_foreach(git_push *push,

src/remote.c

-6
Original file line numberDiff line numberDiff line change
@@ -2160,12 +2160,6 @@ int git_remote_push(git_remote *remote, git_strarray *refspecs, const git_push_o
21602160
if ((error = git_push_finish(push)) < 0)
21612161
goto cleanup;
21622162

2163-
if (!git_push_unpack_ok(push)) {
2164-
error = -1;
2165-
giterr_set(GITERR_NET, "error in the remote while trying to unpack");
2166-
goto cleanup;
2167-
}
2168-
21692163
if (cbs->push_update_reference &&
21702164
(error = git_push_status_foreach(push, cbs->push_update_reference, cbs->payload)) < 0)
21712165
goto cleanup;

tests/network/remote/local.c

-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ void test_network_remote_local__push_to_bare_remote(void)
216216
cl_git_pass(git_push_new(&push, localremote));
217217
cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
218218
cl_git_pass(git_push_finish(push));
219-
cl_assert(git_push_unpack_ok(push));
220219

221220
/* Clean up */
222221
git_push_free(push);
@@ -262,7 +261,6 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
262261
cl_git_pass(git_push_new(&push, localremote));
263262
cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
264263
cl_git_pass(git_push_finish(push));
265-
cl_assert(git_push_unpack_ok(push));
266264

267265
/* Clean up */
268266
git_push_free(push);
@@ -305,7 +303,6 @@ void test_network_remote_local__push_to_non_bare_remote(void)
305303
cl_git_pass(git_push_new(&push, localremote));
306304
cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
307305
cl_git_fail_with(git_push_finish(push), GIT_EBAREREPO);
308-
cl_assert_equal_i(0, git_push_unpack_ok(push));
309306

310307
/* Clean up */
311308
git_push_free(push);
@@ -452,7 +449,6 @@ void test_network_remote_local__update_tips_for_new_remote(void) {
452449
cl_git_pass(git_push_new(&push, new_remote));
453450
cl_git_pass(git_push_add_refspec(push, "refs/heads/master"));
454451
cl_git_pass(git_push_finish(push));
455-
cl_assert(git_push_unpack_ok(push));
456452

457453
/* Update tips and make sure remote branch has been created */
458454
cl_git_pass(git_push_update_tips(push, NULL, NULL));

0 commit comments

Comments
 (0)