123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #!/usr/bin/env bash
- set -euo pipefail
- scriptloc=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
- replace() {
- keyword=$1
- string=$2
- python << END
- with open("${scriptloc}/slides.md") as slides:
- content = slides.read()
- string = """${string}"""
- with open("${scriptloc}/slides.md", "w") as slides:
- slides.write(content.replace(r"${keyword}", string))
- END
- }
- mdprint() {
- cmd=$*
- echo '```bash'
- echo '$' ${cmd}
- eval ${cmd}
- echo '```'
- }
- tmpdir=$(mktemp -d)
- pushd ${tmpdir}
- # delete temporary directory on script exit
- trap "rm -fr ${tmpdir}" 0
- # Initialise repository
- mdprint git init
- git config --local user.name "Achilleas Koutsou"
- git config --local user.email "ak@example.com"
- # No objects here yet
- mdprint tree -F .git/objects
- # Add a README and commit
- mdprint 'echo "# Understanding Git: Presentation slides repository" > README.md'
- mdprint git add README.md
- firstcommit=$(mdprint 'git commit -m "Initial commit: Add README"')
- replace "::firstcommit::" "${firstcommit}"
- # Check the object store again
- firstobjectstore=$(mdprint tree -F .git/objects)
- replace "::firstobjectstore::" "${firstobjectstore}"
- filepaths1=$(find .git/objects -type f)
- # git cat-file on each object
- for path in ${filepaths1}; do
- prefix=${path:13:2}
- rest=${path:16}
- full=${prefix}${rest}
- type=$(git cat-file -t ${full})
- cattype=$(mdprint git cat-file -t ${full})
- catprint=$(mdprint git cat-file -p ${full})
- replace "::catt${type}1::" "${cattype}"
- replace "::catp${type}1::" "${catprint}"
- done
- # Let's make one more commit so we can see the parent
- mdprint 'echo -e "# Understanding Git\n\n> Achilleas Koutsou\n\n2018-11-14" > slides.md'
- mdprint git add slides.md
- mdprint 'git commit -m "Add first presentation slide"'
- # Check the object store again
- mdprint tree -F .git/objects
- secondobjectstore=$(mdprint find .git/objects -type f)
- replace "::secondobjectstore::" "${secondobjectstore}"
- filepaths2=$(find .git/objects -type f)
- # git cat-file on each *new* object
- for path in ${filepaths2}; do
- if echo ${filepaths1} | grep ${path} &> /dev/null; then
- continue
- fi
- prefix=${path:13:2}
- rest=${path:16}
- full=${prefix}${rest}
- mdprint git cat-file -t ${full}
- mdprint git cat-file -p ${full}
- type=$(git cat-file -t ${full})
- cattype=$(mdprint git cat-file -t ${full})
- catprint=$(mdprint git cat-file -p ${full})
- replace "::catt${type}2::" "${cattype}"
- replace "::catp${type}2::" "${catprint}"
- if git cat-file -p ${full} | grep "Understanding Git" &> /dev/null; then
- slidesfirstver=${full}
- fi
- done
- echo "--------------------------"
- # Add a new slide
- mdprint 'echo -e "\n\n# Part 1\n## Porcelain and Plumbing" >> slides.md'
- mdprint git add slides.md
- mdprint 'git commit -m "Add second presentation slide"'
- # Check the object store again
- thirdobjectstore=$(mdprint find .git/objects -type f)
- replace "::thirdobjectstore::" "${thirdobjectstore}"
- filepaths3=$(find .git/objects -type f)
- # git cat-file on each *new* object
- for path in ${filepaths3}; do
- if echo ${filepaths2} | grep ${path} &> /dev/null; then
- continue
- fi
- prefix=${path:13:2}
- rest=${path:16}
- full=${prefix}${rest}
- mdprint git cat-file -t ${full}
- mdprint git cat-file -p ${full}
- type=$(git cat-file -t ${full})
- cattype=$(mdprint git cat-file -t ${full})
- catprint=$(mdprint git cat-file -p ${full})
- replace "::catt${type}3::" "${cattype}"
- replace "::catp${type}3::" "${catprint}"
- done
- mdprint git cat-file -p ${slidesfirstver}
- mdprint git cat-file -t HEAD
- mdprint git cat-file -t master
- catpmaster=$(mdprint git cat-file -p master)
- replace "::catpmaster::" "${catpmaster}"
- mdprint git cat-file -t master~1
- mdprint git cat-file -t master~1:
- mdprint git cat-file -p master~1:slides.md
- mdprint git cat-file -p master~1:README.md
- mdprint git cat-file -p master:README.md
- rpheada=$(mdprint git rev-parse HEAD)
- replace "::rpheada::" "${rpheada}"
- rpmastera=$(mdprint git rev-parse master)
- replace "::rpmastera::" "${rpmastera}"
- catpheada=$(mdprint git cat-file -p HEAD)
- replace "::catpheada::" "${catpheada}"
- rpheadtld1a=$(mdprint git rev-parse HEAD~1)
- replace "::rpheadtld1a::" "${rpheadtld1a}"
- catpmastertld1clna=$(mdprint git cat-file -p master~1:)
- replace "::catpmastertld1clna::" "${catpmastertld1clna}"
- catpmastertld1rdma=$(mdprint git rev-parse master~1:README.md)
- replace "::catpmastertld1rdma::" "${catpmastertld1rdma}"
- mdprint git branch demo-code
- rpmasterdemohead=$(mdprint git rev-parse master demo-code HEAD)
- replace "::rpmasterdemohead::" "${rpmasterdemohead}"
- mdprint git checkout demo-code
- mdprint 'echo "#!/usr/bin/env bash" > demoscript'
- mdprint 'chmod +x demoscript'
- mdprint 'git add demoscript'
- mdprint 'git commit -m "Add demoscript"'
- rpmasterb=$(mdprint git rev-parse master)
- replace "::rpmasterb::" "${rpmasterb}"
- rpdemob=$(mdprint git rev-parse demo-code)
- replace "::rpdemob::" "${rpdemob}"
- rpheadb=$(mdprint git rev-parse HEAD)
- replace "::rpheadb::" "${rpheadb}"
- mdprint git checkout master
- rpmasterc=$(mdprint git rev-parse master)
- replace "::rpmasterc::" "${rpmasterc}"
- rpdemoc=$(mdprint git rev-parse demo-code)
- replace "::rpdemoc::" "${rpdemoc}"
- rpheadc=$(mdprint git rev-parse HEAD)
- replace "::rpheadc::" "${rpheadc}"
- mdprint ls
- mdprint 'echo -e "\n\n# Part 2\n## What is Git?" >> slides.md'
- mdprint git add slides.md
- mdprint 'git commit -m "Add third presentation slide"'
- rpmasterdemod=$(mdprint git rev-parse master~1 demo-code~1)
- replace "::rpmasterdemod::" "${rpmasterdemod}"
- gitloga=$(mdprint git log -n 2)
- replace "::gitloga::" "${gitloga}"
- gitlogb=$(mdprint 'git log --pretty=format:"Commit: %h | Parent: %p | Tree: %t %n Message: %s%n"')
- replace "::gitlogb::" "${gitlogb}"
- gitlogc=$(mdprint 'git log --graph --oneline master demo-code')
- replace "::gitlogc::" "${gitlogc}"
- exit
- # ---------------
- mdprint git log --graph master demo-code
- mdprint 'git log --graph --pretty=format:"Commit: %H%n Message: %s%n Parent: %P%n Tree: %T%n%n" master demo-code'
- git log --reverse --pretty=format:"Commit: %H%n Message: %s%n Parent: %P%n Tree: %T%n%n"
|