#!/bin/bash set -x # First of all as we are using git update-index and don't want to mess arround with saving the current state # We check if there is any staged files check-git-status() { git status --porcelain | grep -e ^A -e ^M && echo "You first need to clean you git staging status to use future-me" && exit 1 } create-new-bug() { readonly bug="$1" last_ref=$(git show-ref refs/notes/devtools/future-me | cut -d ' ' -f 1) echo $last_ref if [ -n "$last_ref" ] then git read-tree $last_ref else git read-tree --empty fi object_id=$(echo "$1" | git hash-object -w --stdin) echo $object_id file_path=${object_id:0:2}/${object_id:2} git update-index --add --cacheinfo 100644 $object_id $file_path tree_id=$(git write-tree) files_to_unstage=$(git update-index --refresh | cut -d ' ' -f 1 | cut -d ':' -f 1) git update-index --remove $files_to_unstage if [ -n "$last_ref" ] then add_parent="$last_ref" commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id -p $add_parent) else commit_id=$(echo 'future-me: created a new bug for you' | git commit-tree $tree_id) fi git update-ref refs/notes/devtools/future-me $commit_id } show-bugs() { #git ls-tree --full-tree -r refs/notes/devtools/future-me for i in $(git ls-tree --full-tree -r refs/notes/devtools/future-me | cut -d ' ' -f 3 | cut -f 1 | tr '\n' ' '); do git cat-file -p $i ; done } main() { readonly command="$1" readonly payload="${*:2}" case $command in new) echo create new bug "$payload" #"${*:2}" check-git-status last_tree="$(git --no-pager log -1 --format="%H" | tr --delete '\n')" echo $last_tree create-new-bug "$payload" git read-tree "$last_tree" ;; show) echo show all bugs show-bugs ;; *) echo unknown command "$@" ;; esac } main "$@"