export: Create subdirectories before copying the patch files
[guilt.git] / guilt-import
blob0e4e0372a5f8cdb30f8711dff30c5e1a281b8572
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 USAGE="[-P <patch> ] <patch_file>"
7 . guilt
9 case "$1" in
10 -P)
11 newname="$2"
12 oldname="$3"
15 newname=`dirname "$1"`
16 oldname="$1"
18 esac
20 if [ $# -lt 1 -o $# -gt 3 -o -z "$newname" -o -z "$oldname" ]; then
21 usage
24 # make sure that there are no unapplied changes
25 if ! must_commit_first; then
26 die "Uncommited changes detected. Refresh first."
29 if [ ! -e "$oldname" ]; then
30 die "Specified file does not exist."
33 if [ -e "$GUILT_DIR/$branch/$newname" ]; then
34 die "Already tracking a patch under that name."
37 # create any directories as needed
38 mkdir_dir=`dirname "$GUILT_DIR/$branch/$newname"`
39 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
41 cp "$oldname" "$GUILT_DIR/$branch/$newname"
43 # insert the patch into the series file
44 series_insert_patch "$newname"