lorikeet-heimdal: apply_heimdal: Only show the Heimdal part of the patch to cherry...
[metze/heimdal/wip.git] / apply_heimdal.sh
1 #!/bin/bash
2
3 [ $# == 2 ] || {
4     echo "Usage: apply_heimdal.sh <lorikeet_path>"
5     exit 1
6 }
7
8 LORIKEET_PATH="$1"
9 IMPORT_HASH="$2"
10 S4PATH="$PWD"
11
12 pushd $LORIKEET_PATH || exit 1
13 git reset --hard 
14 git am --abort
15 popd
16
17 try_patch() {
18     commit="$1"
19     git format-patch --stdout $commit -1 source4/heimdal > "$commit".patch
20     sed -i 's|/source4/heimdal/|/|g' "$commit".patch
21     sed -i "s|^---$|(cherry picked from Samba commit $commit)\n---|g" "$commit".patch
22     pushd $LORIKEET_PATH || exit 1
23     git reset --hard
24     echo
25     if patch -p1 --forward < "$S4PATH/$commit.patch"; then
26         echo
27         echo "Commit $commit can apply - applying"
28         git reset --hard
29         git am "$S4PATH/$commit.patch"
30     else
31         echo
32         echo "Commit $commit does not apply cleanly"
33         echo
34     fi
35     popd || exit 1
36 }
37
38 commits="$(git log --pretty=oneline --reverse $IMPORT_HASH..HEAD -- source4/heimdal | cut -d' ' -f1)"
39 for c in $commits; do
40     git log $c -1
41     echo -n "Try apply? [Y/n] "
42     read answer
43     case $answer in
44         n*)
45             continue
46             ;;
47          *)
48             try_patch $c
49             ;;
50     esac
51 done