Created
June 18, 2012 14:36
-
-
Save nulltoken/2948680 to your computer and use it in GitHub Desktop.
[revparse] Troubleshooting the probing logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
retrieve_head() { | |
local oid=$(git reflog HEAD@{0} -n 1 --format=format:%H); | |
echo "$oid" | |
} | |
add_commit() { | |
echo "$1" > file.txt | |
git add . | |
git commit -m "$1" > /dev/null | |
echo "$(retrieve_head)" | |
} | |
init() { | |
rm -rf ./revparse-probe-repo | |
mkdir revparse-probe-repo && cd revparse-probe-repo | |
git init . | |
commit_oid=$(add_commit Commit) | |
branch_target=$(add_commit Branch) | |
tag_target=$(add_commit Tag) | |
symref_target=$(add_commit Symref) | |
echo $symref_target > ./.git/refs/heads/symtarget | |
initial_head=$(retrieve_head) | |
} | |
create_symref() { | |
echo "ref: refs/heads/symtarget" > "./.git/$1" | |
} | |
create_tag() { | |
echo $tag_target > "./.git/refs/tags/$1" | |
} | |
create_branch() { | |
echo $branch_target > "./.git/refs/heads/$1" | |
} | |
# $1 = commit-ish | |
# $2 = expected | |
# $3 = current | |
# $4 = operation | |
# $5 = message | |
check_result() { | |
if [ "$2" != "$3" ]; then | |
echo "fail - $4 $1 (expected: $2 - retrieved: $3)" | |
else | |
echo "$5" | |
fi | |
} | |
test_checkout() { | |
git checkout -f -q "$1" | |
local head=$(retrieve_head) | |
check_result "$1" "$2" "$head" "chekout" "$3" | |
} | |
test_reset() { | |
git reset --hard -q "$1" | |
local head=$(retrieve_head) | |
check_result "$1" "$2" "$head" "reset" "$3" | |
} | |
test_log() { | |
local oid=$(git log $1 -n 1 --format=format:%H) | |
check_result "$1" "$2" "$oid" "log" "$3" | |
} | |
cleanup() { | |
rm -rf "./.git/refs/heads/$commit_oid" | |
rm -rf "./.git/refs/tags/$commit_oid" | |
rm -rf "./.git/$commit_oid" | |
echo "$commit_oid" > "./.git/refs/heads/master" | |
echo "ref: refs/heads/master" > "./.git/HEAD" | |
git reset --hard -q | |
} | |
init | |
echo "Commit: $commit_oid"; | |
echo "Branch target: $branch_target"; | |
echo "Tag target: $tag_target"; | |
echo "Symref target: $symref_target"; | |
echo "HEAD: $(retrieve_head)" | |
echo | |
test_checkout $commit_oid $commit_oid "Can checkout an oid" | |
cleanup | |
create_symref "$commit_oid" | |
create_tag "$commit_oid" | |
test_checkout $commit_oid $commit_oid "Can checkout an oid even if there's a symref and a tag with the same name" | |
create_branch "$commit_oid" | |
test_checkout $commit_oid $branch_target "Can checkout a branch even if there's an oid, a tag and a symref with the same name" | |
cleanup | |
test_reset $commit_oid $commit_oid "Can reset to an oid" | |
cleanup | |
create_symref "$commit_oid" | |
create_tag "$commit_oid" | |
create_branch "$commit_oid" | |
test_reset $commit_oid $commit_oid "Can reset to an oid even if there's a symref, a branch and a tag with the same name" | |
test_log $commit_oid $commit_oid "Can log to an oid even if there's a symref, a branch and a tag with the same name" | |
cleanup | |
create_branch "deadbeef" | |
test_log "deadbeef" $branch_target "Can log to a branch" | |
create_tag "deadbeef" | |
test_log "deadbeef" $tag_target "Can log to a tag even if there's a branch with the same name" | |
create_symref "deadbeef" | |
test_log "deadbeef" $symref_target "Can log to a symref even if there's a branch and a tag with the same name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment