Skip to content

Commit 392181d

Browse files
committed
update-ref --stdin: skip trailing space
1 parent 5c0d062 commit 392181d

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

builtin/update-ref.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ static const char *parse_arg(const char *next, struct strbuf *arg)
4747
return next;
4848
}
4949

50+
static const char *skip_trailing_space(const char *next)
51+
{
52+
if (line_termination)
53+
while (*next && *next != line_termination && isspace(*next))
54+
next++;
55+
return next;
56+
}
57+
5058
/*
5159
* Parse the reference name immediately after "command SP". If not
5260
* -z, then handle C-quoting. Return a pointer to a newly allocated
@@ -263,6 +271,7 @@ static void parse_cmd_update(struct ref_transaction *transaction,
263271
have_old = !parse_next_oid(&next, end, &old_oid, "update", refname,
264272
PARSE_SHA1_OLD);
265273

274+
next = skip_trailing_space(next);
266275
if (*next != line_termination)
267276
die("update %s: extra input: %s", refname, next);
268277

@@ -351,6 +360,7 @@ static void parse_cmd_create(struct ref_transaction *transaction,
351360
if (is_null_oid(&new_oid))
352361
die("create %s: zero <new-oid>", refname);
353362

363+
next = skip_trailing_space(next);
354364
if (*next != line_termination)
355365
die("create %s: extra input: %s", refname, next);
356366

t/t1400-update-ref.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ test_expect_success 'stdin fails create with no new value' '
629629
test_expect_success 'stdin fails create with too many arguments' '
630630
echo "create $a $m $m" >stdin &&
631631
test_must_fail git update-ref --stdin <stdin 2>err &&
632-
grep "fatal: create $a: extra input: $m" err
632+
grep "fatal: create $a: extra input: $m" err
633633
'
634634

635635
test_expect_success 'stdin fails update with no ref' '
@@ -647,7 +647,7 @@ test_expect_success 'stdin fails update with no new value' '
647647
test_expect_success 'stdin fails update with too many arguments' '
648648
echo "update $a $m $m $m" >stdin &&
649649
test_must_fail git update-ref --stdin <stdin 2>err &&
650-
grep "fatal: update $a: extra input: $m" err
650+
grep "fatal: update $a: extra input: $m" err
651651
'
652652

653653
test_expect_success 'stdin fails delete with no ref' '

0 commit comments

Comments
 (0)