1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/bin/sh
set -e
TREEONLY=false
if [ "$1" = "--tree-only" ]; then
TREEONLY=true
dsc_file=`readlink -f "$2"`
else
dsc_file=`readlink -f "$1"`
fi
if ! [ -d .git -o "$GIT_WORK_TREE" != "" ]; then
echo "$0: must be run from the top level of your git work tree." >&2
echo "$0: alternatively, set GIT_WORK_TREE." >&2
exit 2
fi
if [ "`git status --porcelain`" != "" ]; then
echo "$0: working tree must be clean to continue." >&2
exit 2
fi
tmpdir=`mktemp --tmpdir -d git-dsc-commit.XXXXXXXXXX`
cleanup() { rm -Rf "$tmpdir"; }
trap cleanup EXIT
(cd "$tmpdir" && dpkg-source -x --skip-patches "$dsc_file" > /dev/null)
extracted_dir=`find "$tmpdir" -mindepth 1 -maxdepth 1 -type d`
if ! $TREEONLY; then
debian_version=`cd "$extracted_dir" && dpkg-parsechangelog --count 1|grep-dctrl -nsVersion .`
debian_version_tag=`echo "$debian_version"|sed 's/:/_/g;s/~/_/g'`
if [ -z "$tag" ]; then
tag=$debian_version_tag
fi
if [ "`git tag -l "$tag"`" != "" ]; then
echo "Version $tag is already tagged." >&2
exit 1
fi
cat > "$tmpdir/commit_msg" <<EOT
Import version $debian_version ($tag)
Imported using git-dsc-commit.
EOT
cat > "$tmpdir/tag_msg" <<EOT
Tagged using git-dsc-commit.
EOT
fi
GIT_WORK_TREE="$extracted_dir" git add -fA
if [ "`GIT_WORK_TREE="$extracted_dir" git status --porcelain`" = "" ]; then
echo "No changes to import." >&2
exit 1
fi
if $TREEONLY; then
git write-tree
else
git commit -qF "$tmpdir/commit_msg"
git tag -a -F "$tmpdir/tag_msg" "$tag"
fi
git reset --hard >/dev/null
git clean -fxd >/dev/null
|