summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2005-06-08 20:40:54 +0000
committerAndreas Gruenbacher <agruen@suse.de>2005-06-08 20:40:54 +0000
commitcea07eed0d536c242fc59dc9da1dd3036299b710 (patch)
tree9023e1a5ffd724d2b5ea62e42a639cbc10b8001f
parente661b1ad2b5289110262640ae9fb3fd0f396872f (diff)
downloadquilt-cea07eed0d536c242fc59dc9da1dd3036299b710.tar.gz
- Add rename command from Jean Delvare <khali@linux-fr.org>.
-rw-r--r--Makefile.in2
-rw-r--r--bash_completion12
-rw-r--r--quilt.changes5
-rw-r--r--quilt/.cvsignore1
-rw-r--r--quilt/rename.in111
-rw-r--r--test/rename.test69
6 files changed, 198 insertions, 2 deletions
diff --git a/Makefile.in b/Makefile.in
index 297b393..e9ca301 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -58,7 +58,7 @@ DIRT += $(BIN_IN:%=bin/%)
QUILT_IN := add applied delete diff edit files fold fork graph grep \
import mail new next patches pop previous push refresh remove \
- series setup snapshot top unapplied upgrade
+ rename series setup snapshot top unapplied upgrade
QUILT_SRC := $(QUILT_IN:%=%.in)
QUILT := $(QUILT_IN)
diff --git a/bash_completion b/bash_completion
index 68d1b51..3c0719f 100644
--- a/bash_completion
+++ b/bash_completion
@@ -97,7 +97,7 @@ _quilt_completion()
# quilt sub commands
cmds='add applied delete diff edit files fold fork graph grep \
import new next patches pop previous push refresh remove \
- series setup snapshot top unapplied'
+ rename series setup snapshot top unapplied'
# if no command were given, complete on commands
if [[ $COMP_CWORD -eq 1 ]] ; then
@@ -230,6 +230,16 @@ _quilt_completion()
;;
esac
;;
+ rename)
+ case $prev in
+ -p)
+ COMPREPLY=( $( compgen -W "$(quilt series)" -- $cur ) )
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W "-p" -- $cur ) )
+ ;;
+ esac
+ ;;
series)
COMPREPLY=( $( compgen -W "-n -v -h" -- $cur ) )
;;
diff --git a/quilt.changes b/quilt.changes
index 4151a03..7bf7641 100644
--- a/quilt.changes
+++ b/quilt.changes
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Wed Jun 8 22:28:12 CEST 2005 - agruen@suse.de
+
+- Add rename command from Jean Delvare <khali@linux-fr.org>.
+
+-------------------------------------------------------------------
Wed Jun 8 17:29:44 CEST 2005 - agruen@suse.de
- Add testcase for diff --no-index.
diff --git a/quilt/.cvsignore b/quilt/.cvsignore
index 699f006..ba968c8 100644
--- a/quilt/.cvsignore
+++ b/quilt/.cvsignore
@@ -18,6 +18,7 @@ previous
push
refresh
remove
+rename
rest
series
setup
diff --git a/quilt/rename.in b/quilt/rename.in
new file mode 100644
index 0000000..4c5a4aa
--- /dev/null
+++ b/quilt/rename.in
@@ -0,0 +1,111 @@
+#! @BASH@
+
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# See the COPYING and AUTHORS files for more details.
+
+# Read in library functions
+if [ "$(type -t patch_file_name)" != function ]
+then
+ if ! [ -r @SCRIPTS@/patchfns ]
+ then
+ echo "Cannot read library @SCRIPTS@/patchfns" >&2
+ exit 1
+ fi
+ . @SCRIPTS@/patchfns
+fi
+
+usage()
+{
+ printf $"Usage: quilt rename [-p patch] new_name\n"
+ if [ x$1 = x-h ]
+ then
+ printf $"
+Rename the topmost or named patch.
+
+-p patch
+ Patch to rename.
+"
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+options=`getopt -o p:h -- "$@"`
+
+if [ $? -ne 0 ]
+then
+ usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+ case "$1" in
+ -p)
+ if ! patch=$(find_patch $2)
+ then
+ printf $"Patch %s is not in series\n" "$2" >&2
+ exit 1
+ fi
+ shift 2 ;;
+ -h)
+ usage -h ;;
+ --)
+ shift
+ break ;;
+ esac
+done
+
+if [ $# -ne 1 ]
+then
+ usage
+fi
+
+if [ ! -n "$patch" ]
+then
+ patch=$(top_patch)
+ if [ -z "$patch" ]
+ then
+ printf $"No patches applied\n" >&2
+ exit 1
+ fi
+fi
+
+new_patch=${1#$QUILT_PATCHES/}
+
+if patch_in_series $new_patch || \
+ [ -d "$QUILT_PC/$new_patch" ] || \
+ [ -e "$(patch_file_name $new_patch)" ]
+then
+ printf $"Patch %s exists already, please choose a different name\n" \
+ "$(print_patch $new_patch)" >&2
+ exit 1
+fi
+
+if ( is_applied $patch && \
+ ( ! rename_in_db "$patch" "$new_patch" || \
+ ! mv "$QUILT_PC/$patch" "$QUILT_PC/$new_patch" ) ) || \
+ ! rename_in_series "$patch" "$new_patch" || \
+ ( [ -e "$(patch_file_name $patch)" ] && \
+ ! mv "$(patch_file_name $patch)" \
+ "$(patch_file_name $new_patch)" )
+then
+ printf $"Renaming of patch %s to %s failed\n" \
+ "$(print_patch $patch)" \
+ "$(print_patch $new_patch)" >&2
+ exit 1
+fi
+
+printf $"Patch %s renamed to %s\n" \
+ "$(print_patch $patch)" \
+ "$(print_patch $new_patch)"
+
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
diff --git a/test/rename.test b/test/rename.test
new file mode 100644
index 0000000..c8cf146
--- /dev/null
+++ b/test/rename.test
@@ -0,0 +1,69 @@
+ $ mkdir d
+ $ cd d
+
+ $ cat > announce.txt
+ < A short summary of the fixes are below.
+
+ $ quilt new original-name.diff
+ > Patch %{P}original-name.diff is now on top
+
+ $ quilt add announce.txt
+ > File announce.txt added to patch %{P}original-name.diff
+
+ $ cat > announce.txt
+ < The diffstat and short summary of the fixes are below.
+
+ $ quilt refresh
+ > Refreshed patch %{P}original-name.diff
+
+ $ quilt series -v
+ > = %{P}original-name.diff
+
+ $ ls -1 .pc
+ > applied-patches
+ > original-name.diff
+
+ $ cat .pc/applied-patches
+ > original-name.diff
+
+ $ quilt rename _tmp_name.diff
+ > Patch %{P}original-name.diff renamed to %{P}_tmp_name.diff
+
+ $ quilt series -v
+ > = %{P}_tmp_name.diff
+
+ $ ls -1 .pc
+ > _tmp_name.diff
+ > applied-patches
+
+ $ cat .pc/applied-patches
+ > _tmp_name.diff
+
+ $ quilt pop
+ > Removing patch %{P}_tmp_name.diff
+ > Restoring announce.txt
+ >
+ > No patches applied
+
+ $ quilt series -v
+ > %{P}_tmp_name.diff
+
+ $ ls -1 .pc
+
+ $ quilt rename -p random_name.diff final.name.diff
+ > Patch random_name.diff is not in series
+
+ $ quilt rename final.name.diff
+ > No patches applied
+
+ $ quilt rename -p _tmp_name.diff _tmp_name.diff
+ > Patch %{P}_tmp_name.diff exists already, please choose a different name
+
+ $ quilt rename -p _tmp_name.diff final.name.diff
+ > Patch %{P}_tmp_name.diff renamed to %{P}final.name.diff
+
+ $ quilt series -v
+ > %{P}final.name.diff
+
+ $ cd ..
+ $ rm -rf d