Skip to content

Commit 2347eb3

Browse files
authored
Merge pull request libgit2#6362 from sven-of-cord/main
push: revparse refspec source, so you can push things that are not refs
2 parents 4d47ad6 + 211c971 commit 2347eb3

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/libgit2/push.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,18 @@ static int calculate_work(git_push *push)
385385
git_vector_foreach(&push->specs, i, spec) {
386386
if (spec->refspec.src && spec->refspec.src[0]!= '\0') {
387387
/* This is a create or update. Local ref must exist. */
388-
if (git_reference_name_to_id(
389-
&spec->loid, push->repo, spec->refspec.src) < 0) {
390-
git_error_set(GIT_ERROR_REFERENCE, "no such reference '%s'", spec->refspec.src);
388+
389+
git_object *obj;
390+
int error = git_revparse_single(&obj, push->repo, spec->refspec.src);
391+
392+
if (error < 0) {
393+
git_object_free(obj);
394+
git_error_set(GIT_ERROR_REFERENCE, "src refspec %s does not match any", spec->refspec.src);
391395
return -1;
392396
}
397+
398+
git_oid_cpy(git_object_id(obj), &spec->loid);
399+
git_object_free(obj);
393400
}
394401

395402
/* Remote ref may or may not (e.g. during create) already exist. */

tests/libgit2/online/push.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,28 @@ void test_online_push__bad_refspecs(void)
841841

842842
void test_online_push__expressions(void)
843843
{
844-
/* TODO: Expressions in refspecs doesn't actually work yet */
845-
const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" };
844+
const char *specs_left_expr[] = {
845+
"refs/heads/b3~1:refs/heads/b2",
846+
"b4:refs/heads/b4",
847+
"fa38b91f199934685819bea316186d8b008c52a2:refs/heads/b5",
848+
"951bbbb:refs/heads/b6"
849+
};
850+
push_status exp_stats[] = {
851+
{ "refs/heads/b2", 1 },
852+
{ "refs/heads/b4", 1 },
853+
{ "refs/heads/b5", 1 },
854+
{ "refs/heads/b6", 1 }
855+
};
856+
expected_ref exp_refs[] = {
857+
{ "refs/heads/b2", &_oid_b2 },
858+
{ "refs/heads/b4", &_oid_b4 },
859+
{ "refs/heads/b5", &_oid_b5 },
860+
{ "refs/heads/b6", &_oid_b6 }
861+
};
846862

847-
/* TODO: Find a more precise way of checking errors than a exit code of -1. */
848863
do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
849-
NULL, 0,
850-
NULL, 0, -1, 0, 0);
864+
exp_stats, ARRAY_SIZE(exp_stats),
865+
exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
851866
}
852867

853868
void test_online_push__notes(void)

0 commit comments

Comments
 (0)