2 # archives2git - generate a Git history from a series of release tarballs
3 # Copyright © 2013 Géraud Meyer <graud@gmx.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 PROGRAM_NAME
="archives2git"
20 # archives2git [<options>] [--] <archives>
24 GIT_WORK_TREE
=${GIT_WORK_TREE-.}
38 shift; GIT_WORK_TREE
=$1 ;;
48 shift; ADDARGS
="$ADDARGS $1" ;;
50 shift; CIARGS
="$CIARGS $1" ;;
52 shift; FILTERHEAD
=$1 ;;
54 echo "$PROGRAM_NAME version $PROGRAM_VERSION"
57 echo "$0: unknown option $1" >&2
71 # git repository check
72 cd "$GIT_WORK_TREE" &&
73 { test -d .git || git rev-parse
--git-dir >/dev
/null
; } ||
75 echo "$0: error not in a git repository" >&2
78 test -z "$(git status --porcelain)" &&
79 git update-index
-q --refresh ||
81 echo "$0: unstaged files or dirty index" >&2
91 aunpack
-X "$TMPDIR" "$arch"
95 [ -e "$file" ] ||
continue
96 [ "$file" = "." -o "$file" = ".." -o "$file" = ".git" ] && continue
97 eval "$FILTER" ||
( git
rm -r "$file" ||
rm -R "$file" )
99 for file in "$TMPDIR"/* "$TMPDIR"/.
*
101 [ -e "$file" ] ||
continue
102 file=${file#$TMPDIR/}
103 [ "$file" = "." -o "$file" = ".." ] && continue
104 name
=$
(eval "$RENAME")
107 [ ! -e .
/"$name" ] ||
rm -R .
/"$name"
108 mv "$TMPDIR"/"$file" .
/"$name"
109 git add
$ADDARGS .
/"$name"
111 rm -R "$TMPDIR"/"$file"
114 git commit
-m "$(eval "$TITLE")${BODY:+$NL$BODY}" \
115 ${DATE:+--date "$(eval "$DATE")"} $CIARGS
116 if [ -n "$FILTERHEAD" ]
119 git filter-branch
$FILTERHEAD -- HEAD^..HEAD
120 rm -R "$(git rev-parse --git-dir)"/refs
/original
/