chiark / gitweb /
tg-patch: add support for generating patches against worktree and index
[topgit.git] / tg.sh
diff --git a/tg.sh b/tg.sh
index b64fc3a0f8ab2958298daa12f55242b5362c4cdf..1762f03e9522d96b01ffa6ee2f028e1464ffc174 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -17,6 +17,27 @@ die()
        exit 1
 }
 
+# cat_file "topic:file"
+# Like `git cat-file blob $1`, but topics '(i)' and '(w)' means index and worktree
+cat_file()
+{
+       arg="$1"
+       case "$arg" in
+       '(w):'*)
+               arg=$(echo "$arg" | tail --bytes=+5)
+               cat "$arg"
+               return
+               ;;
+       '(i):'*)
+               # ':file' means cat from index
+               arg=$(echo "$arg" | tail --bytes=+5)
+               git cat-file blob ":$arg"
+               ;;
+       *)
+               git cat-file blob "$arg"
+       esac
+}
+
 # setup_hook NAME
 setup_hook()
 {