-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support detached head, symlinks, executable bit; annotate optional code
- Loading branch information
Joe Mou
committed
Apr 21, 2019
1 parent
55e2c63
commit b77784b
Showing
9 changed files
with
75 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,101 +13,124 @@ get_md5() { | |
} | ||
|
||
header 'Initializing repo... [zit, init]' | ||
[[ $1 == --keep ]] && { keep=1; shift; } | ||
ZIT="${1-zit}" | ||
trap 'echo -e "\e[31mFAIL\e[0m"' ERR | ||
repo="$PWD/test.tmp" | ||
rm -rf "$repo" | ||
zit init "$repo" | ||
[[ $1 != --keep ]] && trap 'rm -rf "$repo"' EXIT | ||
$ZIT init "$repo" | ||
[[ -n $keep ]] || trap 'rm -rf "$repo"' EXIT | ||
cd "$repo" | ||
[[ $(<.zit/HEAD) == 'ref: refs/heads/master' ]] | ||
[[ ${ZIT::1} == / ]] || ZIT="../$ZIT" | ||
|
||
header 'Writing a blob object... [hash-object]' | ||
echo "I'm a little teapot" > lullaby | ||
[[ $(zit hash-object blob lullaby) == 3eb7f9afc452afe452b99d478d89264380622248 ]] | ||
[[ $($ZIT hash-object blob lullaby) == 3eb7f9afc452afe452b99d478d89264380622248 ]] | ||
|
||
header 'Reading an object... [cat-file]' | ||
[[ $(zit cat-file -t 3eb7f9afc452afe452b99d478d89264380622248 ) == blob ]] | ||
[[ $(zit cat-file blob 3eb7f9afc452afe452b99d478d89264380622248 ) == "I'm a little teapot" ]] | ||
[[ $($ZIT cat-file -t 3eb7f9afc452afe452b99d478d89264380622248 ) == blob ]] | ||
[[ $($ZIT cat-file blob 3eb7f9afc452afe452b99d478d89264380622248 ) == "I'm a little teapot" ]] | ||
|
||
header 'Writing to the index... [index.py]' | ||
PYTHONPATH=.. /usr/bin/python -c 'import index; index.write_index([("lullaby", 0100644, "\x3e\xb7\xf9\xaf\xc4\x52\xaf\xe4\x52\xb9\x9d\x47\x8d\x89\x26\x43\x80\x62\x22\x48")])' | ||
PYTHONPATH=$(dirname "$ZIT") /usr/bin/python -c 'import index; index.write_index([("lullaby", 0100644, "\x3e\xb7\xf9\xaf\xc4\x52\xaf\xe4\x52\xb9\x9d\x47\x8d\x89\x26\x43\x80\x62\x22\x48")])' | ||
[[ $(get_md5 .zit/index) == 06432001fc95f78cd6353321f7c95009 ]] | ||
|
||
header 'Adding a file to the index... [add]' | ||
echo here > handle | ||
zit add handle | ||
[[ $(zit cat-file blob 012ea92e81171f5ef7486696878656c5263cf722 ) == here ]] | ||
$ZIT add handle | ||
[[ $($ZIT cat-file blob 012ea92e81171f5ef7486696878656c5263cf722 ) == here ]] | ||
[[ $(get_md5 .zit/index) == 61728e18ee75d24576d9ea2b626fb1ff ]] | ||
|
||
header 'Reading the index... [index.py]' | ||
[[ $(PYTHONPATH=.. /usr/bin/python -c 'import index; print index.read_index()') == "[('handle', 33188, '\x01.\xa9.\x81\x17\x1f^\xf7Hf\x96\x87\x86V\xc5&<\xf7\"'), ('lullaby', 33188, '>\xb7\xf9\xaf\xc4R\xaf\xe4R\xb9\x9dG\x8d\x89&C\x80b\"H')]" ]] | ||
[[ $(PYTHONPATH=$(dirname "$ZIT") /usr/bin/python -c 'import index; print index.read_index()') == "[('handle', 33188, '\x01.\xa9.\x81\x17\x1f^\xf7Hf\x96\x87\x86V\xc5&<\xf7\"'), ('lullaby', 33188, '>\xb7\xf9\xaf\xc4R\xaf\xe4R\xb9\x9dG\x8d\x89&C\x80b\"H')]" ]] | ||
|
||
header 'Writing the index to a tree object... [write-tree]' | ||
initial_tree=$(zit write-tree) | ||
initial_tree=$($ZIT write-tree) | ||
[[ $initial_tree == f65ccd4f10cb3416c7be6601bafd2371a784054f ]] | ||
|
||
header 'Writing an initial commit object... [commit-tree]' | ||
export ZIT_AUTHOR_NAME='Miss Teapot' [email protected] | ||
initial_commit=$(echo initial commit | zit commit-tree $initial_tree) | ||
[[ $(zit cat-file commit $initial_commit ) =~ ^"tree $initial_tree | ||
author Miss Teapot <[email protected]> "[0-9]*\ [+-][0-9]{4}" | ||
committer Miss Teapot <[email protected]> "[0-9]*\ [+-][0-9]{4}" | ||
initial_commit=$(echo initial commit | $ZIT commit-tree $initial_tree) | ||
[[ $($ZIT cat-file commit $initial_commit ) =~ ^"tree $initial_tree | ||
author "[^\<]*" <"[^\>]*"> "[0-9]*\ [+-][0-9]{4}" | ||
committer "[^\<]*" <"[^\>]*"> "[0-9]*\ [+-][0-9]{4}" | ||
initial commit"$ ]] | ||
|
||
header 'Create a branch ref [update-ref]' | ||
zit update-ref refs/heads/initial $initial_commit | ||
$ZIT update-ref refs/heads/initial $initial_commit | ||
[[ $(<.zit/refs/heads/initial) == $initial_commit ]] | ||
|
||
header 'Read HEAD symbolic ref [symbolic-ref]' | ||
[[ $(zit symbolic-ref HEAD) == refs/heads/master ]] | ||
[[ $($ZIT symbolic-ref HEAD) == refs/heads/master ]] | ||
|
||
header 'Birth master branch [update-ref, get-sha1-basic, rev-parse]' | ||
zit update-ref HEAD $initial_commit | ||
[[ $(zit rev-parse HEAD) == $initial_commit ]] | ||
$ZIT update-ref HEAD $initial_commit | ||
[[ $($ZIT rev-parse HEAD) == $initial_commit ]] | ||
|
||
header 'Delete and create a branch [branch]' | ||
zit branch -d initial | ||
$ZIT branch -d initial | ||
[[ ! -f .zit/refs/heads/initial ]] | ||
zit branch initial | ||
$ZIT branch initial | ||
[[ $(<.zit/refs/heads/initial) == $initial_commit ]] | ||
|
||
header 'Writing another commit object... [commit, commit-tree]' | ||
echo 'short and stout' > lullaby | ||
zit add lullaby | ||
echo 'second verse' | EDITOR=tee zit commit > /dev/null | ||
$ZIT add lullaby | ||
EDITOR=tee $ZIT commit <<< 'second verse' > /dev/null | ||
second_tree=3c1bea2d45d260a3836794e04a4bbef34e3c2459 | ||
[[ $(zit cat-file commit $(zit rev-parse HEAD) ) =~ ^"tree $second_tree | ||
second_commit=$($ZIT rev-parse HEAD) | ||
[[ $($ZIT cat-file commit $second_commit ) =~ ^"tree $second_tree | ||
parent $initial_commit | ||
author Miss Teapot <[email protected]> "[0-9]*\ [+-][0-9]{4}" | ||
committer Miss Teapot <[email protected]> "[0-9]*\ [+-][0-9]{4}" | ||
author "[^\<]*" <"[^\>]*"> "[0-9]*\ [+-][0-9]{4}" | ||
committer "[^\<]*" <"[^\>]*"> "[0-9]*\ [+-][0-9]{4}" | ||
second verse"$ ]] | ||
|
||
header 'Parse ^ and ~ revisions [rev-parse]' | ||
[[ $(zit rev-parse HEAD^) == $initial_commit ]] | ||
[[ $(zit rev-parse HEAD~1) == $initial_commit ]] | ||
[[ $(zit rev-parse initial~0) == $initial_commit ]] | ||
[[ $($ZIT rev-parse HEAD^) == $initial_commit ]] | ||
[[ $($ZIT rev-parse HEAD~1) == $initial_commit ]] | ||
[[ $($ZIT rev-parse initial~0) == $initial_commit ]] | ||
|
||
header 'Parse ^{type} revisions [rev-parse]' | ||
[[ $(zit rev-parse HEAD^{tree}) == $second_tree ]] | ||
[[ $(zit rev-parse HEAD^^{tree}) == $initial_tree ]] | ||
[[ $($ZIT rev-parse HEAD^{tree}) == $second_tree ]] | ||
[[ $($ZIT rev-parse HEAD^^{tree}) == $initial_tree ]] | ||
|
||
header 'Reading tree object into the index... [read-tree]' | ||
zit read-tree $initial_tree | ||
$ZIT read-tree $initial_tree | ||
[[ $(get_md5 .zit/index) == 61728e18ee75d24576d9ea2b626fb1ff ]] | ||
|
||
header 'Checkout from the index [checkout-index]' | ||
zit checkout-index | ||
$ZIT checkout-index | ||
[[ $(<lullaby) == "I'm a little teapot" ]] | ||
|
||
header 'Update HEAD symbolic ref [symbolic-ref]' | ||
zit symbolic-ref HEAD refs/heads/initial | ||
$ZIT symbolic-ref HEAD refs/heads/initial | ||
[[ $(<.zit/HEAD) == 'ref: refs/heads/initial' ]] | ||
|
||
header 'Checkout master branch [checkout]' | ||
zit checkout master | ||
$ZIT checkout master | ||
[[ $(<lullaby) == 'short and stout' ]] | ||
[[ $(<.zit/HEAD) == 'ref: refs/heads/master' ]] | ||
|
||
header 'Checkout detached HEAD [checkout]' | ||
$ZIT checkout HEAD | ||
[[ $(<.zit/HEAD) == $second_commit ]] | ||
|
||
header 'Commit executable file, symlink, and directory [add]' | ||
chmod +x handle | ||
mkdir and | ||
ln -s ../handle and/spout | ||
git add handle and/spout | ||
EDITOR=tee $ZIT commit <<< 'first stanza' > /dev/null | ||
[[ $($ZIT rev-parse HEAD^{tree}) == 6a8ad12fa34d4f1ea64abb28c8ae143b1e8fde40 ]] | ||
|
||
header 'Checkout a new branch [checkout, checkout-index]' | ||
rm -rf handle and | ||
$ZIT checkout -b stanza | ||
[[ $(<.zit/HEAD) == 'ref: refs/heads/stanza' ]] | ||
[[ -x handle ]] | ||
[[ $(python -c 'import os; print os.readlink("and/spout")') == ../handle ]] | ||
|
||
[[ -n $keep ]] || { rm -rf "$repo"; trap '' EXIT; } | ||
header PASS |