11 USAGE="usage: zit COMMAND FILE [ARGS...]"
23 echo "Set up a git repository under .zit.FILE to track changes for FILE."
24 echo "File must be a regular file and in the current directory."
27 echo " init Synonym for track"
28 echo " list Synonym for tracked"
29 echo " track Start tracking changes to FILE"
30 echo " tracked List tracked files in current directory"
32 echo "See 'zit help git' or 'git help' for git commands."
41 test $ZIT_FILE || abort "Please specify a file"
42 test -f $ZIT_FILE || abort "No such file $ZIT_FILE"
43 test $ZIT_FILE = "`basename $ZIT_FILE`" || abort "Sorry, Zit only works on files in the current directory"
45 export GIT_WORK_TREE="`pwd`"
47 # first, check if a repo exists already, looking for
48 # .zit/file.git or .file.git, in that order
49 # if neither is found, and .zit exists, set the repo dir
50 # to .zit/file.git, otherwise set it to .file.git
51 GIT_DIR="$ZIT_DIR/$ZIT_FILE.git"
52 if ! test -d "$GIT_DIR"; then
53 GIT_DIR=".$ZIT_FILE.git"
54 if ! test -d "$GIT_DIR"; then
55 test -d "$ZIT_DIR" && GIT_DIR="$ZIT_DIR/$ZIT_FILE.git"
64 test -e $GIT_DIR && abort "$GIT_DIR exists, is $ZIT_FILE tracked already?"
65 mkdir $GIT_DIR && echo "Initializing Zit repository in $GIT_DIR"
66 test -d $GIT_DIR || abort "Failed to create $GIT_DIR"
67 git init || abort "Failed to initialize Git repository in $GIT_DIR"
68 rm -rf $GIT_DIR/{hooks,branches,refs/tags,objects/pack,description}
69 echo "*" > $GIT_DIR/info/exclude
70 git add -f $ZIT_FILE || abort "Failed to add $ZIT_FILE"
71 git commit "$@" || abort "Failed to make first commit for $ZIT_FILE"
73 if test -d "$ZIT_DIR"; then
74 echo "$ZIT_DIR exists already"
77 test -e $ZIT_DIR && abort "$ZIT_DIR exists but it's not a directory, cannot continue"
83 export GIT_WORK_TREE="`pwd`"
85 for file in "$ZIT_DIR"/*.git .*.git; do
86 if ! test -e $file; then
89 export GIT_DIR="$file"
93 # TODO show actual file status
96 # if $GIT_DIR is empty, no files were found
97 test "$GIT_DIR" || echo "(no files tracked by zit)"
113 # Most commands will work with the generic catch-all mechanism used
114 # below, but some of them require a more thorough analysis of the
115 # parameters to decide whether $ZIT_FILE should be put back into the
116 # parameter list or not. For example,
117 # $ zit commit somefile
118 # wouldn't do what one expects it to do, unless 'add' is run first,
121 # wouldn't work either), however
122 # $ zit commit somefile -a
123 # would work correctly. So we handle some commands separately (for the
124 # moment just add and commit)
128 git $cmd "$@" "$ZIT_FILE"
130 # the raw<command> method can be used to not replicate $ZIT_FILE in the