repair: new command to repair repository state
[guilt.git] / guilt-import
blob4d73cc9a30e73c1c4165190afba16ab5dce5515e
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 # 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"