summaryrefslogtreecommitdiff
path: root/quilt/patches/shell-subcommand
blob: 48df2ab5c930178fc742d566c693574c8e244c38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Description: Implement a new "quilt shell" command
 The command launches a shell in a duplicate environment. After exiting
 the shell, any modifications made in this environment are applied to the
 topmost patch.
Author: Josselin Mouette <joss@debian.org>
Bug-Debian: http://bugs.debian.org/526141

---
 quilt/shell.in |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

--- /dev/null
+++ b/quilt/shell.in
@@ -0,0 +1,67 @@
+#! @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 $QUILT_DIR/scripts/patchfns ]
+        then
+                echo "Cannot read library $QUILT_DIR/scripts/patchfns" >&2
+                exit 1
+        fi
+        . $QUILT_DIR/scripts/patchfns
+fi
+
+if [ "$1" = "-h" ]; then
+    printf $"Usage: quilt shell [command]\n"
+    printf $"
+Launch a shell in a duplicate environment. After exiting the shell, any
+modifications made in this environment are applied to the topmost patch.
+
+If a command is specified, it is executed instead of launching the shell.
+"
+    exit 0
+fi
+
+tmpdir=$(mktemp -d /tmp/quilt-XXXXXX)
+
+cp -a . $tmpdir
+
+(
+    cd $tmpdir/"$SUBDIR"
+    if [ $# -gt 0 ]; then
+        exec "$@"
+    else
+        $SHELL
+    fi
+)
+
+# Find new directories
+( cd $tmpdir; find . -type d ! -path ./"$QUILT_PC"/\* ! -path ./"$QUILT_PATCHES"/\* ) | while read dir; do
+    if [ ! -d "$dir" ]; then
+        mkdir -p "$dir"
+    fi
+done
+
+# New and modified files
+( cd $tmpdir; find . -type f ! -path ./"$QUILT_PC"/\* ! -path ./"$QUILT_PATCHES"/\* ) | while read file; do
+    if [ ! -f "$file" ] || ! diff -q "$file" $tmpdir/"$file" > /dev/null 2>&1; then
+        quilt_command add "$file"
+        cp -a $tmpdir/"$file" "$file"
+    fi
+done
+
+# Removed files
+( find . -type f ! -path ./"$QUILT_PC"/\* ! -path ./"$QUILT_PATCHES"/\* ) | while read file; do
+    if [ ! -f $tmpdir/"$file" ]; then
+        quilt_command add "$file"
+        rm -f "$file"
+    fi
+done
+
+rm -rf $tmpdir
--- a/bash_completion
+++ b/bash_completion
@@ -97,7 +97,7 @@ _quilt_completion()
     # quilt sub commands 
     cmds='add annotate applied delete diff edit files fold fork graph \
           grep header import mail new next patches pop previous push refresh \
-	  remove rename revert series setup snapshot top unapplied'
+	  remove rename revert series setup shell snapshot top unapplied'
 
     # if no command were given, complete on commands
     if [[ $COMP_CWORD -eq 1 ]] ; then