#!/bin/bash # # git-kickin.sh - helper app for quick git init (e.g. for creating patches) # Copyright (C) 2008 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. help() { echo "" >&2 echo "Usage: $0 { | | | . | auto-exclude }" >&2 echo "" >&2 echo "With tar-file as argument:" >&2 echo " Create a new .git directory. Use the content of the tar file (minus" >&2 echo " top-level directory) as tree for the automatic initial commit." >&2 echo "" >&2 echo "With dot as argument:" >&2 echo " Create a new .git directory. Use the content of working directory as" >&2 echo " tree for the automatic initial commit. " >&2 echo "" >&2 echo "With 'auto-exclude' as argument:" >&2 echo " Add all unknown files to .git/info/exclude file." >&2 echo "" >&2 exit 1 } if ( if [ "$1" = "auto-exclude" ]; then set -ex git ls-files -o >> .git/info/exclude elif [ "$1" = "." ]; then set -ex git init git add . git commit -m init else if [ -z "$1" -o ! -f "$1" -o -e .git ]; then help fi case "$1" in *.tar) set -ex mkdir git-kickin-tmp tar x -C git-kickin-tmp -f - < "$1" ;; *.tar.gz) set -ex mkdir git-kickin-tmp tar x -z -C git-kickin-tmp -f - < "$1" ;; *.tar.bz2) set -ex mkdir git-kickin-tmp tar x -j -C git-kickin-tmp -f - < "$1" ;; *) help ;; esac cd git-kickin-tmp/* git init git add . git commit -m init cd ../.. mv git-kickin-tmp/*/.git . rm -rf git-kickin-tmp fi ); then echo "READY." exit 0 else exit 1 fi