diff -uN common/cvs-import.sh common.new/cvs-import.sh
--- common/cvs-import.sh	2005-10-14 14:26:06.000000000 -0400
+++ common.new/cvs-import.sh	2005-12-29 00:38:37.000000000 -0500
@@ -8,11 +8,15 @@
 # $Id: cvs-import.sh,v 1.10 2005/10/14 18:26:06 sopwith Exp $
 
 # Initial setup
-CVSTREE=${CVSTREE:=extras}
-TOPLEVEL=${TOPLEVEL:=rpms}
+CVSTREE=${CVSTREE:-extras}
+TOPLEVEL=${TOPLEVEL:-rpms}
 
 # Check that we're being run from a good location
 MYDIR=$(dirname $0)
+pushd ${MYDIR} &>/dev/null
+MYDIR=${PWD}
+popd &> /dev/null
+
 if [ ! -f ${MYDIR}/CVS/Root ] ; then
     echo "ERROR: You need to run this script from the 'common' checkout" >&2
     exit 1
@@ -26,10 +30,10 @@
 CVSROOT=$(cat ${MYDIR}/CVS/Root)
 
 # We need a writable directory for temporary checkouts and CVS work
-WORKDIR="/tmp"
 if test -w $(pwd) ; then
-    WORKDIR="$(pwd)"
+    WORKDIR=${WORKDIR:-"$(pwd)"}
 fi
+WORKDIR=${WORKDIR:-"/tmp"}
 
 # short usage help
 Usage() {
@@ -42,8 +46,7 @@
 CVSROOT    = $CVSROOT
 BRANCH     = ${BRANCH:-devel}
 
-The package can also be imported on a PRE-EXISTING branch using the 
-"-b BRANCH" flag. This script can not create new branches for you.
+The package can also be imported to a branch using the "-b BRANCH" flag.
 EOF
     exit 1
 }
@@ -58,8 +61,7 @@
 	# the import
 	-b | --branch )
 	    shift
-	    BRANCH="$1"
-	    if [ -z "$BRANCH" ] ; then
+	    if [ -z "$1" ] ; then
 		echo "ERROR: --branch requires an argument"
 		Usage
 		exit -1
@@ -68,6 +70,11 @@
 	    if [ "$BRANCH" = "HEAD" -o "$BRANCH" = "devel" ] ; then
 		BRANCH=
 	    fi
+	    grep -q "^$1:" ${MYDIR}/branches && BRANCH="$1" || {
+		echo "ERROR: branch '$1' not recognized"
+		Usage
+		exit -1
+	    }
 	    ;;
 
 	-m | --message )
@@ -154,26 +161,65 @@
 # Now make sure we have the requested to operate on a branch
 if [ -n "$BRANCH" ] ; then
     # check that this branch exists before importing anything into it
-    if [ -z "$(grep ""^$NAME-$BRANCH[[:space:]]"" modules 2>/dev/null)" ] ; then
-	# XXX: allow the creation of branches
-	cat <<EOF
-ERROR: You have requested to import a package into the branch $BRANCH of the
-module $NAME, but according to the modules file this branch does not exist.
-
-This tool allows you to import packages only on pre-existing branches. If you
-would like the new branch created, please email sysadmin-devel@redhat.com.
+    grep -q "^$NAME-$BRANCH[[:space:]]" modules || {
+	grep -q "^$NAME"$'\t' modules || {
+	    cat << EOF
+ERROR: Cannot create a new branch on a non-existent module. Please import
+the package normally first.
 EOF
-	exit -1
-    fi
+	    exit -1
+	}
+	[ -f "${MYDIR}/Makefile.template.module" -a -f "${MYDIR}/Makefile.template.branch" ] || {
+	    cat << EOF
+ERROR: Makefile templates not found. Make sure you have checked out
+'common' completely. ${MYDIR}
+EOF
+	    exit -1
+	}
+	# Create the branch
+	cvs -Q update modules && {
+	    echo "Creating new branch for $NAME: $BRANCH"
+	    cat << EOF >> modules
+$NAME-$BRANCH    	&$NAME-$BRANCH-dir &common
+$NAME-$BRANCH-dir	-d $NAME $TOPLEVEL/$NAME/$BRANCH
+EOF
+	    sed -i "s/^$BRANCH.*$/& \&$NAME-$BRANCH-dir/" modules
+	    cvs -Q commit -m "Added new branch $BRANCH on $NAME"
+	    pushd $TMPDIR >/dev/null
+	    $CVS -Q checkout -l $TOPLEVEL/$NAME
+	    mkdir $TOPLEVEL/$NAME/$BRANCH
+	    pushd $TOPLEVEL/$NAME &> /dev/null
+	    cvs -Q add $BRANCH
+	    popd &> /dev/null
+	    cvs -Q commit -m "Creating branch directory $BRANCH on $NAME"
+	    $CVS -Q checkout -l $TOPLEVEL/$NAME/$BRANCH
+	    cd $TOPLEVEL/$NAME/$BRANCH
+	    touch sources .cvsignore
+	    echo "$BRANCH" > branch
+	    cp ${MYDIR}/Makefile.template.branch Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
+	    cvs -Q add Makefile sources .cvsignore branch
+            # commit all the added stuff
+	    cd .. && cvs -Q commit -m "Setup of branch $BRANCH of $NAME"
+	    popd &> /dev/null
+	}
+    }
 fi
 
 # Figure out if we need to import a new module
 if [ -z "$(grep ""^$NAME[[:space:]]"" modules 2>/dev/null)" ] ; then
+    [ -f ${MYDIR}/Makefile.template.module -a -f ${MYDIR}/Makefile.template.branch ] || {
+	cat << EOF
+ERROR: Makefile templates not found. Make sure you have checked out
+'common' completely. 2
+EOF
+	exit -1
+    }
     # This is a new module, it does not exist
     cvs -Q update modules && \
 	echo "Creating new module: $NAME" && \
 	echo -e "$NAME\t\t$TOPLEVEL/$NAME &common" >> modules && \
-	cvs -Q commit -m "Added new module: $NAME" >/dev/null && \
+	cvs -Q commit -m "Added new module: $NAME" && \
 	{
 	    # Create a new module
 	    pushd $TMPDIR >/dev/null
@@ -184,55 +230,19 @@
 	    # handle the top level stuff
 	    cd $NAME
 	    touch import.log
-	    cat >Makefile <<EOF
-# Top level Makefile for module $NAME
-all : CVS/Root common-update
-	@cvs update
-
-common-update : common
-	@cd common && cvs update
-
-common : CVS/Root
-	@cvs checkout common
-
-CVS/Root :
-	@echo "ERROR: This does not look like a CVS checkout" && exit 1
-
-clean :
-	@find . -type f -name *~ -exec rm -fv {} \;
-EOF
+	    cp ${MYDIR}/Makefile.template.module Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
 	    cvs -Q add Makefile import.log
 	    # handle the module build
 	    cd devel
 	    touch sources .cvsignore
-	    cat >Makefile <<EOF
-# Makefile for source rpm: $NAME
-# \$Id\$
-NAME := $NAME
-SPECFILE = \$(firstword \$(wildcard *.spec))
-
-define find-makefile-common
-for d in common ../common ../../common ; do if [ -f \$\$d/Makefile.common ] ; then if [ -f \$\$d/CVS/Root -a -w \$\$/Makefile.common ] ; then cd \$\$d ; cvs -Q update ; fi ; echo "\$\$d/Makefile.common" ; break ; fi ; done
-endef
-
-MAKEFILE_COMMON := \$(shell \$(find-makefile-common))
-
-ifeq (\$(MAKEFILE_COMMON),)
-# attept a checkout
-define checkout-makefile-common
-test -f CVS/Root && { cvs -Q -d \$\$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
-endef
-
-MAKEFILE_COMMON := \$(shell \$(checkout-makefile-common))
-endif
-
-include \$(MAKEFILE_COMMON)
-EOF
+	    cp ${MYDIR}/Makefile.template.branch Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
 	    cvs -Q add Makefile sources .cvsignore
             # commit all the added stuff
-	    cd .. && cvs -Q commit -m "Setup of module $NAME" >/dev/null
+	    cd .. && cvs -Q commit -m "Setup of module $NAME"
 	    popd >/dev/null
-	    rm -rf $TMPDIR/$TOPLEVEL
+#	    rm -rf $TMPDIR/$TOPLEVEL
 	} && echo "Entry for module '$NAME' created."
 else
     echo "Module '$NAME' already exists..."
@@ -350,7 +360,7 @@
 popd >/dev/null
 
 # We no longer need this
-rm -rf $TMP2
+#rm -rf $TMP2
 
 # setup finished
 echo "$LOG_ENTRY:$(date +%s)" >> ./import.log
@@ -363,7 +373,7 @@
 )
 cvs -Q update && \
     echo "cvs commit..." && \
-    cvs -Q commit -m "$MESSAGE" >/dev/null && echo "Commit Complete" && \
+    cvs -Q commit -m "$MESSAGE" && echo "Commit Complete" && \
     cd ${BRANCH} && cvs -Q tag "${TAG}" && echo "Tagging '${TAG}' complete."
 
 # Clean up
diff -uN common/Makefile.template.branch common.new/Makefile.template.branch
--- common/Makefile.template.branch	1969-12-31 19:00:00.000000000 -0500
+++ common.new/Makefile.template.branch	2005-12-28 00:03:44.000000000 -0500
@@ -0,0 +1,21 @@
+# Makefile for source rpm: @@NAME@@
+# $Id: Makefile,v 1.1 2005/04/10 03:47:56 spot Exp $
+NAME := @@NAME@@
+SPECFILE = $(firstword $(wildcard *.spec))
+
+define find-makefile-common
+for d in common ../common ../../common ; do if [ -f $$d/Makefile.common ] ; then if [ -f $$d/CVS/Root -a -w $$/Makefile.common ] ; then cd $$d ; cvs -Q update ; fi ; echo "$$d/Makefile.common" ; break ; fi ; done
+endef
+
+MAKEFILE_COMMON := $(shell $(find-makefile-common))
+
+ifeq ($(MAKEFILE_COMMON),)
+# attept a checkout
+define checkout-makefile-common
+test -f CVS/Root && { cvs -Q -d $$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
+endef
+
+MAKEFILE_COMMON := $(shell $(checkout-makefile-common))
+endif
+
+include $(MAKEFILE_COMMON)
diff -uN common/Makefile.template.module common.new/Makefile.template.module
--- common/Makefile.template.module	1969-12-31 19:00:00.000000000 -0500
+++ common.new/Makefile.template.module	2005-12-28 00:03:23.000000000 -0500
@@ -0,0 +1,15 @@
+# Top level Makefile for module @@NAME@@
+all : CVS/Root common-update
+	@cvs update
+
+common-update : common
+	@cd common && cvs update
+
+common : CVS/Root
+	@cvs checkout common
+
+CVS/Root :
+	@echo "ERROR: This does not look like a CVS checkout" && exit 1
+
+clean :
+	@find . -type f -name *~ -exec rm -fv {} \;
