From e3fcb9c5c77aeafe1ff8c8d51f9e92be3e1aa275 Mon Sep 17 00:00:00 2001 From: "G.raud" Date: Sat, 31 Aug 2013 22:11:17 +0200 Subject: [PATCH] archives2git: new sh script --- archives2git | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 archives2git diff --git a/archives2git b/archives2git new file mode 100755 index 0000000..3db2e22 --- /dev/null +++ b/archives2git @@ -0,0 +1,101 @@ +#!/bin/sh +# archives2git - generate a Git history from a series of release tarballs +# Copyright © 2013 Géraud Meyer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +PROGRAM_NAME="archives2git" +PROGRAM_VERSION="0" +# Usage: +# archives2git [] [--] + +# parameters +RENAME='echo "$file"' +FILTER='true $file' +DATE='' +TITLE='echo "$arch"' +BODY= +ARGS= +while [ $# -gt 0 ] +do + case $1 in + --rename) + shift; RENAME=$1 ;; + --filter-file) + shift; FILTER=$1 ;; + --date) + shift; DATE=$1 ;; + --title) + shift; TITLE=$1 ;; + --body) + shift; BODY=$1 ;; + --git-arg) + shift; ARGS="$ARGS $1" ;; + --version) + echo "$PROGRAM_NAME version $PROGRAM_VERSION" + exit ;; + --?*) + echo "$0: unknown option $1" >&2 + exit 255 ;; + --) + shift; break ;; + *) + break ;; + esac + shift +done +# git repository check +test ! -d .git && ! git rev-parse --git-dir >/dev/null && +{ + echo "$0: error not in a git repository" >&2 + exit 255 +} +# setup +TMPDIR=$(mktemp -d) +NL=' +' + +# main +set -e +for arch +do + aunpack -X "$TMPDIR" "$arch" + for file in * .* + do + [ -e "$file" ] || continue + [ "$file" = "." -o "$file" = ".." -o "$file" = ".git" ] && continue + git rm -r "$file" || rm -R "$file" + done + for file in "$TMPDIR"/* "$TMPDIR"/.* + do + [ -e "$file" ] || continue + file=${file#$TMPDIR/} + [ "$file" = "." -o "$file" = ".." ] && continue + name=$(eval "$RENAME") + if [ -n "$name" ] + then mv "$TMPDIR"/"$file" ./"$name" + else rm "$TMPDIR"/"$file" + fi + done + for file in * .* + do + [ -e "$file" ] || continue + [ "$file" = "." -o "$file" = ".." -o "$file" = ".git" ] && continue + eval "$FILTER" && git add "$file" + done + git commit -m "$(eval "$TITLE")${BODY:+$NL$BODY}" \ + ${DATE:+--date "$(eval "$DATE")"} $ARGS +done + +# +rmdir "$TMPDIR" -- 2.11.4.GIT