8 echo "Usage: nogit <command>"
10 echo "Available commands are:"
15 echo "See 'nogit help' for more details"
20 echo "Usage: nogit <command>"
22 echo "Possible commands are described below:"
24 echo "nogit clone <command>"
26 echo " Clone a nogit repository into the current directory."
27 echo " This differs from 'git clone' in that it will not create"
28 echo " a new top-level directory but will instead clone the"
29 echo " resulting files into the current directory (which may"
30 echo " already be a local git repository). The object store for"
31 echo " this newly-cloned repository will be a directory named"
32 echo " .nogit rather than .git."
34 echo " The repository to be cloned should be a nogit repository"
35 echo " in the sense that its files are intended to be managed"
36 echo " according to nogit semantics. But other than that, the"
37 echo " repository to be cloned is an actual git repository."
41 echo " Synchronize local and remote changes"
43 echo " For all files managed by a previously-cloned nogit repository"
44 echo " this command will:"
46 echo " * Commit local changes (auto-generated commit message)"
48 echo " * Pull down any new commits from the remote"
50 echo " * Auto-merge local and remote (keeping both sides and"
51 echo " with an auto-generated commit message)"
53 echo " * Push out any new commits generated locally"
60 if [ -e $NOGIT_DIR ]; then
61 echo "Error: .nogit already exists. Cowardly refusing to re-clone."
65 # Clone the repository into a temporary directory
68 git clone "$url" tmp >/dev/null 2>&1
70 # Sanity check that we won't be overwriting any files
73 for file in $(find . -mindepth 1 -a -path ./.git -prune -o -print); do
74 if [ -e "../../$file" ]; then
75 EXISTING+=($(echo "$file" | sed -s 's,^\./,,'))
80 if [ ${#EXISTING[@]} -gt 0 ]; then
81 echo "Error: The following existing files would be overwritten:" >&2
83 for file in ${EXISTING[@]}; do
87 echo "Cowardly refusing to clone" >&2
93 # Now that we've passed the sanity check, install the cloned .git
94 # object store into $NOGIT_DIR, cleanup our temporary files, and
95 # checkout the (known to not be conflicting) files.
96 mv tmp/.git ../$NOGIT_DIR
99 GIT_DIR=$NOGIT_DIR git reset --hard >/dev/null 2>&1
101 echo "Completed nogit clone of $url"
106 # First commit any locally modified nogit files
107 GIT_DIR=$NOGIT_DIR git commit -a -m "nogit-sync commit" >/dev/null 2>&1 || true
109 # Then, fetch and merge any upstream changes
110 GIT_DIR=$NOGIT_DIR git fetch >/dev/null 2>&1
111 GIT_DIR=$NOGIT_DIR git merge -m "nogit-sync merge" >/dev/null 2>&1
113 # Finally, push any new commits up to the upstream repository
114 GIT_DIR=$NOGIT_DIR git push >/dev/null 2>&1
116 echo "Completed nogit sync"
119 if [ $# -lt 1 ]; then
120 echo "Error: missing command name." >&2
130 if [ $# -lt 2 ]; then
131 echo "Error: 'nogit clone' requires the URL of a repository to clone"
144 echo "Error: Unknown command: $cmd" >&2