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.)
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"
}
> 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 &&
> 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 &&
> 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
> 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
> 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
> 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]
> 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 &&
> 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
> 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
'
> 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
'
> 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
'
> 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 &&
> 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
> 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
> 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
> 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 &&
> 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 &&
> 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 &&
> 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 &&
> 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 &&
> 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 &&
> 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 &&
> 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
> 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
> 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 &&
> 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 &&
> 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 &&
> 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
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>#"
}
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
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