{diff,import-commit,new}: fix handling of binary files
[guilt.git] / guilt-import
blob1dcc2aabf607ab3d139619e87f5c0eccf3e8873a
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 USAGE="[-P <patch> ] <patch_file>"
7 . `dirname $0`/guilt
9 case "$1" in
10 -P)
11 newname="$2"
12 oldname="$3"
15 newname=`basename "$1"`
16 oldname="$1"
18 esac
20 if [ $# -lt 1 ] || [ $# -gt 3 ] || [ -z "$newname" ] || [ -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 if ! valid_patchname "$newname"; then
38 die "The specified patch name contains invalid characters (:)."
41 # create any directories as needed
42 mkdir_dir=`dirname "$GUILT_DIR/$branch/$newname"`
43 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
45 cp "$oldname" "$GUILT_DIR/$branch/$newname"
47 # insert the patch into the series file
48 series_insert_patch "$newname"