Skip to content

Commit 2ea49f2

Browse files
KarthikNayakpeff
authored andcommitted
receive-pack: utilize rejected ref error details
In 9d2962a (receive-pack: use batched reference updates, 2025-05-19), git-receive-pack(1) switched to using batched reference updates. This also introduced a regression wherein instead of providing detailed error messages for failed referenced updates, the users were provided generic error messages based on the error type. Now that the updates also contain detailed error message, propagate those to the client via 'rp_error'. The detailed error messages can be very verbose, for e.g. in the files backend, when trying to write a non-commit object to a branch, you would see: ! [remote rejected] 3eaec9ccf3a53f168362a6b3fdeb73426fb9813d -> branch (cannot update ref 'refs/heads/branch': trying to write non-commit object 3eaec9ccf3a53f168362a6b3fdeb73426fb9813d to branch 'refs/heads/branch') Here the refname is repeated multiple times due to how error messages are propagated and filled over the code stack. This potentially can be cleaned up in a future commit. Reported-by: Elijah Newren <newren@gmail.com> Co-authored-by: Jeff King <peff@peff.net> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 274f435 commit 2ea49f2

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

builtin/receive-pack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,11 +1813,14 @@ static void ref_transaction_rejection_handler(const char *refname,
18131813
const char *old_target UNUSED,
18141814
const char *new_target UNUSED,
18151815
enum ref_transaction_error err,
1816-
const char *details UNUSED,
1816+
const char *details,
18171817
void *cb_data)
18181818
{
18191819
struct strmap *failed_refs = cb_data;
18201820

1821+
if (details)
1822+
rp_error("%s", details);
1823+
18211824
strmap_put(failed_refs, refname, (char *)ref_transaction_error_msg(err));
18221825
}
18231826

@@ -1884,6 +1887,7 @@ static void execute_commands_non_atomic(struct command *commands,
18841887
}
18851888

18861889
ref_transaction_for_each_rejected_update(transaction,
1890+
18871891
ref_transaction_rejection_handler,
18881892
&failed_refs);
18891893

@@ -1895,7 +1899,7 @@ static void execute_commands_non_atomic(struct command *commands,
18951899
if (reported_error)
18961900
cmd->error_string = reported_error;
18971901
else if (strmap_contains(&failed_refs, cmd->ref_name))
1898-
cmd->error_string = strmap_get(&failed_refs, cmd->ref_name);
1902+
cmd->error_string = cmd->error_string_owned = xstrdup(strmap_get(&failed_refs, cmd->ref_name));
18991903
}
19001904

19011905
cleanup:

t/t5516-fetch-push.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,4 +1882,19 @@ test_expect_success 'push with F/D conflict with deletion and creation' '
18821882
git push testrepo :refs/heads/branch/conflict refs/heads/branch
18831883
'
18841884

1885+
test_expect_success 'pushing non-commit objects should report error' '
1886+
test_when_finished "rm -rf dest repo" &&
1887+
git init dest &&
1888+
git init repo &&
1889+
1890+
(
1891+
cd repo &&
1892+
test_commit --annotate test &&
1893+
1894+
tagsha=$(git rev-parse test^{tag}) &&
1895+
test_must_fail git push ../dest "$tagsha:refs/heads/branch" 2>err &&
1896+
test_grep "trying to write non-commit object $tagsha to branch ${SQ}refs/heads/branch${SQ}" err
1897+
)
1898+
'
1899+
18851900
test_done

0 commit comments

Comments
 (0)