5 NOGIT_DIR_TMP=$NOGIT_DIR-tmp
9 echo "Usage: nogit <command>"
11 echo "Available commands are:"
16 echo "See 'nogit help' for more details"
21 echo "Usage: nogit <command>"
23 echo "Possible commands are described below:"
25 echo "nogit clone <command>"
27 echo " Clone a nogit repository into the current directory."
28 echo " This differs from 'git clone' in that it will not create"
29 echo " a new top-level directory but will instead clone the"
30 echo " resulting files into the current directory (which may"
31 echo " already be a local git repository). The object store for"
32 echo " this newly-cloned repository will be a directory named"
33 echo " .nogit rather than .git."
35 echo " The repository to be cloned should be a nogit repository"
36 echo " in the sense that its files are intended to be managed"
37 echo " according to nogit semantics. But other than that, the"
38 echo " repository to be cloned is an actual git repository."
42 echo " Synchronize local and remote changes"
44 echo " For all files managed by a previously-cloned nogit repository"
45 echo " this command will:"
47 echo " * Commit local changes (auto-generated commit message)"
49 echo " * Pull down any new commits from the remote"
51 echo " * Auto-merge local and remote (keeping both sides and"
52 echo " with an auto-generated commit message)"
54 echo " * Push out any new commits generated locally"
61 if [ -e $NOGIT_DIR ]; then
62 echo "Error: $NOGIT_DIR already exists. Cowardly refusing to re-clone."
66 if [ -e $NOGIT_DIR_TMP ]; then
67 echo "Error: $NOGIT_DIR_TMP already exists. Was a previosu clone interrupted?"
68 echo "You'll want to clean that up before trying again."
72 # Clone the repository into a temporary directory
75 git clone "$url" tmp >/dev/null 2>&1
77 # Sanity check that we won't be overwriting any files
80 for file in $(find . -mindepth 1 -a -path ./.git -prune -o -print); do
81 if [ -e "../../$file" ]; then
82 EXISTING+=($(echo "$file" | sed -s 's,^\./,,'))
87 if [ ${#EXISTING[@]} -gt 0 ]; then
88 echo "Error: The following existing files would be overwritten:" >&2
90 for file in ${EXISTING[@]}; do
94 echo "Cowardly refusing to clone" >&2
100 # Now that we've passed the sanity check, install the cloned .git
101 # object store into $NOGIT_DIR, cleanup our temporary files, and
102 # checkout the (known to not be conflicting) files.
103 mv tmp/.git ../$NOGIT_DIR
105 rm -rf $NOGIT_DIR_TMP
106 GIT_DIR=$NOGIT_DIR git reset --hard >/dev/null 2>&1
108 echo "Completed nogit clone of $url"
113 # First commit any locally modified nogit files
114 GIT_DIR=$NOGIT_DIR git commit -a -m "nogit-sync commit" >/dev/null 2>&1 || true
116 # Then, fetch and merge any upstream changes
117 GIT_DIR=$NOGIT_DIR git fetch >/dev/null 2>&1
118 GIT_DIR=$NOGIT_DIR git merge -m "nogit-sync merge" >/dev/null 2>&1
120 # Finally, push any new commits up to the upstream repository
121 GIT_DIR=$NOGIT_DIR git push >/dev/null 2>&1
123 echo "Completed nogit sync"
126 if [ $# -lt 1 ]; then
127 echo "Error: missing command name." >&2
137 if [ $# -lt 2 ]; then
138 echo "Error: 'nogit clone' requires the URL of a repository to clone"
151 echo "Error: Unknown command: $cmd" >&2