Zit only works on files in the current directory
[zit] / zit
1 #!/bin/bash
2
3 abort() {
4         echo $1
5         exit 1
6 }
7
8 cmd="$1"
9 shift
10
11 case $cmd in
12         init)
13         file="$1"
14         shift
15         test -f $file || abort "No such file $file"
16         test $file = "`basename $file`" || abort "Sorry, Zit only works on files in the current directory"
17         ZIT_DIR=".zit.$file"
18         test -e $ZIT_DIR && abort "$ZIT_DIR exists already, is $file tracked already?"
19         mkdir $ZIT_DIR && echo "Initializing Zit repository in $ZIT_DIR"
20         test -d $ZIT_DIR || abort "Failed to create $ZIT_DIR"
21         cd $ZIT_DIR
22         git init || abort "Failed to initialize Git repository in $ZIT_DIR" 
23         ln ../$file $file || abort "Failed to link $file into $ZIT_DIR"
24         git add $file || abort "Failed to add $file"
25         git commit "$@" || abort "Failed to make first commit for $file"
26         ;;
27 esac