diff options
author | Jiang Xin <worldhello.net@gmail.com> | 2021-06-17 11:17:27 +0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-06-17 14:12:24 +0900 |
commit | 12d6991cf417465d567c38ba8ae7d59bda7a202f (patch) | |
tree | 9474d49f346d2db497f1bc2b95dacaf61b69128a /t/t5548-push-porcelain.sh | |
parent | 3c06a583398f6630c7162b463ff1acbdf0110f83 (diff) | |
download | git-12d6991cf417465d567c38ba8ae7d59bda7a202f.tar.gz |
test: refactor to use "get_abbrev_oid" to get abbrev oid
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>
Diffstat (limited to 't/t5548-push-porcelain.sh')
-rwxr-xr-x | t/t5548-push-porcelain.sh | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index c8f18a7a12..f11ff57e54 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -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 |