]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test: refactor to use "get_abbrev_oid" to get abbrev oid
authorJiang Xin <worldhello.net@gmail.com>
Thu, 17 Jun 2021 03:17:27 +0000 (11:17 +0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Jun 2021 05:12:24 +0000 (14:12 +0900)
Add new function "get_abbrev_oid" to get abbrev object ID.  This
function has a default value which helps to prepare a nonempty replace
pattern for sed command.  An empty replace pattern may cause sed fail
to allocate memory.

Refactor function "make_user_friendly_and_stable_output" to use
"get_abbrev_oid" to get abbrev object ID.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed:
t/t5411/common-functions.sh
t/t5411/test-0000-standard-git-push.sh
t/t5411/test-0001-standard-git-push--porcelain.sh
t/t5411/test-0022-report-unexpect-ref.sh
t/t5411/test-0023-report-unexpect-ref--porcelain.sh
t/t5411/test-0032-report-with-options.sh
t/t5411/test-0033-report-with-options--porcelain.sh
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
t/t5411/test-0038-report-mixed-refs.sh
t/t5411/test-0039-report-mixed-refs--porcelain.sh
t/t5411/test-0040-process-all-refs.sh
t/t5411/test-0041-process-all-refs--porcelain.sh
t/t5411/test-0050-proc-receive-refs-with-modifiers.sh
t/t5548-push-porcelain.sh

index b9c6adecf50fa4e03fac1009546097cffb76c936..3c747782c1b7fb9b1d12baeae714ef80b1266df4 100644 (file)
@@ -18,6 +18,18 @@ create_commits_in () {
        done
 }
 
+get_abbrev_oid () {
+       oid=$1 &&
+       suffix=${oid#???????} &&
+       oid=${oid%$suffix} &&
+       if test -n "$oid"
+       then
+               echo "$oid"
+       else
+               echo "undefined-oid"
+       fi
+}
+
 # Format the output of git-push, git-show-ref and other commands to make a
 # user-friendly and stable text.  We can easily prepare the expect text
 # without having to worry about changes of the commit ID (full or abbrev.)
@@ -28,12 +40,10 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
        sed \
                -e "s/'/\"/g" \
-               -e "s/$A/<COMMIT-A>/g" \
-               -e "s/$B/<COMMIT-B>/g" \
-               -e "s/$TAG/<TAG-v123>/g" \
+               -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \
+               -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \
+               -e "s/$(get_abbrev_oid $TAG)[0-9a-f]*/<TAG-v123>/g" \
                -e "s/$ZERO_OID/<ZERO-OID>/g" \
-               -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
-               -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
                -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
                -e "/^error: / d"
 }
index d8aafc235c43f08ac9a6d0b761f33febcd4a3f21..ce64bb660ba2da3380dffdad6d4268d92550255a 100644 (file)
@@ -15,7 +15,7 @@ test_expect_success "git-push ($PROTOCOL)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> main
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> main
        >  * [new branch]      HEAD -> next
        EOF
        test_cmp expect actual &&
@@ -69,7 +69,7 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> next
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> next
        >  ! [rejected]        main -> main (non-fast-forward)
        EOF
        test_cmp expect actual &&
@@ -106,7 +106,7 @@ test_expect_success "git-push -f ($PROTOCOL)" '
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic        Z
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c        Z
        > To <URL/of/upstream.git>
-       >  + <OID-B>...<OID-A> main -> main (forced update)
+       >  + <COMMIT-B>...<COMMIT-A> main -> main (forced update)
        >  - [deleted]         next
        >  * [new tag]         v123 -> v123
        >  * [new reference]   main -> refs/review/main/topic
index 2078d0a027775e9efc5f387e0db0b35114f217e6..373ec3d865dba30a8aca2c4944a636843d5482e7 100644 (file)
@@ -15,7 +15,7 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next        Z
        > To <URL/of/upstream.git>
-       >       <COMMIT-B>:refs/heads/main      <OID-A>..<OID-B>
+       >       <COMMIT-B>:refs/heads/main      <COMMIT-A>..<COMMIT-B>
        > *     HEAD:refs/heads/next    [new branch]
        > Done
        EOF
@@ -71,7 +71,7 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/next        Z
        > To <URL/of/upstream.git>
-       >       <COMMIT-B>:refs/heads/next      <OID-A>..<OID-B>
+       >       <COMMIT-B>:refs/heads/next      <COMMIT-A>..<COMMIT-B>
        > !     refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
        > Done
        EOF
@@ -109,7 +109,7 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/main/topic        Z
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/a/b/c        Z
        > To <URL/of/upstream.git>
-       > +     refs/heads/main:refs/heads/main <OID-B>...<OID-A> (forced update)
+       > +     refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
        > -     :refs/heads/next        [deleted]
        > *     refs/tags/v123:refs/tags/v123   [new tag]
        > *     refs/heads/main:refs/review/main/topic  [new reference]
index a2ce7ebdf633cf22379a02e82b1d8e32ab1cdca6..f7a494bdb9d16fb3f25a3ea0884f107afa4a6555 100644 (file)
@@ -26,7 +26,7 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> main
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> main
        >  ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
        EOF
        test_cmp expect actual &&
index 4e56b163f8ee4267d8ec6db679036974b8aed8e7..63c479e975964b876cc48f8293a156321ec21b80 100644 (file)
@@ -26,7 +26,7 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/heads/main        Z
        > To <URL/of/upstream.git>
-       >       <COMMIT-B>:refs/heads/main      <OID-A>..<OID-B>
+       >       <COMMIT-B>:refs/heads/main      <COMMIT-A>..<COMMIT-B>
        > !     HEAD:refs/for/main/topic        [remote rejected] (proc-receive failed to report status)
        > Done
        EOF
index cd4f213a7de3572fdbc9708fe75d3754249259c6..988a4302a67f5b8d4f5453852021614096441351 100644 (file)
@@ -123,7 +123,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head        Z
        > To <URL/of/upstream.git>
-       >    <OID-B>..<OID-A>  HEAD -> refs/pull/123/head
+       >    <COMMIT-B>..<COMMIT-A>  HEAD -> refs/pull/123/head
        EOF
        test_cmp expect actual
 '
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >    <OID-B>..<OID-A>  HEAD -> refs/for/main/topic
+       >    <COMMIT-B>..<COMMIT-A>  HEAD -> refs/for/main/topic
        EOF
        test_cmp expect actual
 '
@@ -189,7 +189,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  HEAD -> refs/for/main/topic
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/for/main/topic
        EOF
        test_cmp expect actual
 '
@@ -243,7 +243,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
        > To <URL/of/upstream.git>
        >  * [new reference]   HEAD -> refs/pull/123/head
        >  * [new reference]   HEAD -> refs/for/a/b/c/topic
-       >  + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
+       >  + <COMMIT-B>...<COMMIT-A> HEAD -> refs/pull/124/head (forced update)
        EOF
        test_cmp expect actual &&
 
index 7433870e40b14366da4c5211ba7c785d35dc54dc..daacb3d69d4af4a18f5516b02f017efbe16f72cf 100644 (file)
@@ -127,7 +127,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head        Z
        > To <URL/of/upstream.git>
-       >       HEAD:refs/pull/123/head <OID-B>..<OID-A>
+       >       HEAD:refs/pull/123/head <COMMIT-B>..<COMMIT-A>
        > Done
        EOF
        test_cmp expect actual
@@ -160,7 +160,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >       HEAD:refs/for/main/topic        <OID-B>..<OID-A>
+       >       HEAD:refs/for/main/topic        <COMMIT-B>..<COMMIT-A>
        > Done
        EOF
        test_cmp expect actual
@@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
        > remote: # post-receive hook        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >       HEAD:refs/for/main/topic        <OID-A>..<OID-B>
+       >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
        > Done
        EOF
        test_cmp expect actual
@@ -251,7 +251,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
        > To <URL/of/upstream.git>
        > *     HEAD:refs/pull/123/head [new reference]
        > *     HEAD:refs/for/a/b/c/topic       [new reference]
-       > +     HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update)
+       > +     HEAD:refs/pull/124/head <COMMIT-B>...<COMMIT-A> (forced update)
        > Done
        EOF
        test_cmp expect actual &&
index e3f456ca5a0827671523532b49f21a815d8c802e..8c8a6c16e10825bd5e16a7db20ac9b0af876a440 100644 (file)
@@ -60,9 +60,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  HEAD -> refs/for/main/topic
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/for/main/topic
        >  * [new reference]   HEAD -> refs/changes/24/124/1
-       >    <OID-A>..<OID-B>  HEAD -> refs/changes/25/125/1
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/changes/25/125/1
        EOF
        test_cmp expect actual &&
 
@@ -136,8 +136,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1        Z
        > To <URL/of/upstream.git>
        >  * [new reference]   HEAD -> refs/changes/24/124/1
-       >    <OID-A>..<OID-B>  HEAD -> refs/for/main/topic
-       >  + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/for/main/topic
+       >  + <COMMIT-B>...<COMMIT-A> HEAD -> refs/changes/25/125/1 (forced update)
        EOF
        test_cmp expect actual &&
 
@@ -198,7 +198,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2        Z
        > To <URL/of/upstream.git>
        >  * [new reference]   HEAD -> refs/changes/23/123/1
-       >    <OID-A>..<OID-B>  HEAD -> refs/changes/24/124/2
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/changes/24/124/2
        EOF
        test_cmp expect actual &&
 
index 7786079ba51aeb1c4e374c56b32fe4650638e0ad..bc44810f33a82a812ce5bb4d18f7e98f294a65d9 100644 (file)
@@ -45,9 +45,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1        Z
        > To <URL/of/upstream.git>
-       >       HEAD:refs/for/main/topic        <OID-A>..<OID-B>
+       >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
        > *     HEAD:refs/changes/24/124/1      [new reference]
-       >       HEAD:refs/changes/25/125/1      <OID-A>..<OID-B>
+       >       HEAD:refs/changes/25/125/1      <COMMIT-A>..<COMMIT-B>
        > Done
        EOF
        test_cmp expect actual &&
@@ -107,8 +107,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1        Z
        > To <URL/of/upstream.git>
        > *     HEAD:refs/changes/24/124/1      [new reference]
-       >       HEAD:refs/for/main/topic        <OID-A>..<OID-B>
-       > +     HEAD:refs/changes/25/125/1      <OID-B>...<OID-A> (forced update)
+       >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
+       > +     HEAD:refs/changes/25/125/1      <COMMIT-B>...<COMMIT-A> (forced update)
        > Done
        EOF
        test_cmp expect actual &&
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2        Z
        > To <URL/of/upstream.git>
        > *     HEAD:refs/changes/23/123/1      [new reference]
-       >       HEAD:refs/changes/24/124/2      <OID-A>..<OID-B>
+       >       HEAD:refs/changes/24/124/2      <COMMIT-A>..<COMMIT-B>
        > Done
        EOF
        test_cmp expect actual &&
index 0990a3f76aa743de106c44611e982e3b892295b0..e63fe7ba1102dab2e75f586e29f149383c21b9a0 100644 (file)
@@ -55,12 +55,12 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> main
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> main
        >  * [new branch]      HEAD -> bar
        >  * [new branch]      HEAD -> baz
        >  * [new reference]   HEAD -> refs/for/next/topic2
        >  * [new branch]      HEAD -> foo
-       >    <OID-A>..<OID-B>  HEAD -> refs/for/main/topic
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/for/main/topic
        >  ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
        >  ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
        EOF
index 7e4d08a939a66679bec048b65f5e53caab829e02..99d17b73afd03e8f50cf05b3ceee18f78687b635 100644 (file)
@@ -55,12 +55,12 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo        Z
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic        Z
        > To <URL/of/upstream.git>
-       >       <COMMIT-B>:refs/heads/main      <OID-A>..<OID-B>
+       >       <COMMIT-B>:refs/heads/main      <COMMIT-A>..<COMMIT-B>
        > *     HEAD:refs/heads/bar     [new branch]
        > *     HEAD:refs/heads/baz     [new branch]
        > *     HEAD:refs/for/next/topic2       [new reference]
        > *     HEAD:refs/heads/foo     [new branch]
-       >       HEAD:refs/for/main/topic        <OID-A>..<OID-B>
+       >       HEAD:refs/for/main/topic        <COMMIT-A>..<COMMIT-B>
        > !     HEAD:refs/for/next/topic1       [remote rejected] (fail to call Web API)
        > !     HEAD:refs/for/next/topic3       [remote rejected] (proc-receive failed to report status)
        > Done
index f67cb2a7b36ff350e13210bc6f6942891af72d01..2f405adefa892b01f80d3291d993ba882fd7cf5b 100644 (file)
@@ -85,11 +85,11 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> bar
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> bar
        >  - [deleted]         foo
-       >  + <OID-B>...<OID-A> HEAD -> main (forced update)
-       >    <OID-A>..<OID-B>  HEAD -> refs/pull/123/head
-       >  + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
+       >  + <COMMIT-B>...<COMMIT-A> HEAD -> main (forced update)
+       >    <COMMIT-A>..<COMMIT-B>  HEAD -> refs/pull/123/head
+       >  + <COMMIT-B>...<COMMIT-A> HEAD -> refs/pull/124/head (forced update)
        EOF
        test_cmp expect actual &&
 
index 7d1a99d3a2048894907a23d10e6a64f845eb2387..c88405792ef57c0ef79880ad7d1909496f471ae8 100644 (file)
@@ -85,11 +85,11 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head        Z
        > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head        Z
        > To <URL/of/upstream.git>
-       >       <COMMIT-B>:refs/heads/bar       <OID-A>..<OID-B>
+       >       <COMMIT-B>:refs/heads/bar       <COMMIT-A>..<COMMIT-B>
        > -     :refs/heads/foo [deleted]
-       > +     HEAD:refs/heads/main    <OID-B>...<OID-A> (forced update)
-       >       HEAD:refs/pull/123/head <OID-A>..<OID-B>
-       > +     HEAD:refs/pull/124/head <OID-B>...<OID-A> (forced update)
+       > +     HEAD:refs/heads/main    <COMMIT-B>...<COMMIT-A> (forced update)
+       >       HEAD:refs/pull/123/head <COMMIT-A>..<COMMIT-B>
+       > +     HEAD:refs/pull/124/head <COMMIT-B>...<COMMIT-A> (forced update)
        > Done
        EOF
        test_cmp expect actual &&
index dba544162c509abd6fb282b65360eb26808b8f8f..31989f018501dab21738fdb92c81af8676662ed1 100644 (file)
@@ -46,7 +46,7 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
        > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/pull/123/head        Z
        > remote: post-receive< <ZERO-OID> <TAG-v123> refs/pull/124/head        Z
        > To <URL/of/upstream.git>
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> refs/pull/123/head
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> refs/pull/123/head
        >  * [new reference]   v123 -> refs/pull/124/head
        EOF
        test_cmp expect actual &&
@@ -116,7 +116,7 @@ test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOC
        > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/124/head        Z
        > To <URL/of/upstream.git>
        >  - [deleted]         refs/pull/123/head
-       >    <OID-A>..<OID-B>  <COMMIT-B> -> topic
+       >    <COMMIT-A>..<COMMIT-B>  <COMMIT-B> -> topic
        >  - [deleted]         v123
        >  * [new reference]   <COMMIT-A> -> refs/pull/124/head
        EOF
index c8f18a7a1219040b352ca9530f682e2d3a768216..f11ff57e5499a1724841d27cd09c61e18108ce8f 100755 (executable)
@@ -26,17 +26,27 @@ create_commits_in () {
        done
 }
 
+get_abbrev_oid () {
+       oid=$1 &&
+       suffix=${oid#???????} &&
+       oid=${oid%$suffix} &&
+       if test -n "$oid"
+       then
+               echo "$oid"
+       else
+               echo "undefined-oid"
+       fi
+}
+
 # Format the output of git-push, git-show-ref and other commands to make a
 # user-friendly and stable text.  We can easily prepare the expect text
 # without having to worry about future changes of the commit ID and spaces
 # of the output.
 make_user_friendly_and_stable_output () {
        sed \
-               -e "s/$A/<COMMIT-A>/g" \
-               -e "s/$B/<COMMIT-B>/g" \
+               -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \
+               -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \
                -e "s/$ZERO_OID/<ZERO-OID>/g" \
-               -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
-               -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
                -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#"
 }
 
@@ -102,9 +112,9 @@ run_git_push_porcelain_output_test() {
                format_and_save_expect <<-EOF &&
                > To <URL/of/upstream.git>
                > =     refs/heads/baz:refs/heads/baz   [up to date]
-               >       <COMMIT-B>:refs/heads/bar       <OID-A>..<OID-B>
+               >       <COMMIT-B>:refs/heads/bar       <COMMIT-A>..<COMMIT-B>
                > -     :refs/heads/foo [deleted]
-               > +     refs/heads/main:refs/heads/main <OID-B>...<OID-A> (forced update)
+               > +     refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
                > *     refs/heads/next:refs/heads/next [new branch]
                > Done
                EOF
@@ -220,7 +230,7 @@ run_git_push_porcelain_output_test() {
                To <URL/of/upstream.git>
                > =     refs/heads/next:refs/heads/next [up to date]
                > -     :refs/heads/baz [deleted]
-               >       refs/heads/main:refs/heads/main <OID-A>..<OID-B>
+               >       refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B>
                > !     refs/heads/bar:refs/heads/bar   [rejected] (non-fast-forward)
                Done
                EOF