lorikeet-heimdal: Add a new script to help merging patches from Samba4 to heimdal
[lorikeet-heimdal.git] / apply_heimdal.sh
1 #!/bin/bash
2
3 [ $# == 1 ] || {
4     echo "Usage: apply_heimdal.sh <lorikeet_path>"
5     exit 1
6 }
7
8 LORIKEET_PATH="$1"
9
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 > "$commit".patch
20     sed -i 's|/source4/heimdal/|/|g' "$commit".patch
21     pushd $LORIKEET_PATH || exit 1
22     git reset --hard
23     echo
24     if patch -p1 --forward < "$S4PATH/$commit.patch"; then
25         echo
26         echo "Commit $commit can apply - applying"
27         git reset --hard
28         git am "$S4PATH/$commit.patch"
29     else
30         echo
31         echo "Commit $commit does not apply cleanly"
32         echo
33     fi
34     popd || exit 1
35 }
36
37 commits="$(git log --pretty=oneline --reverse --since='1 months ago' heimdal | cut -d' ' -f1)"
38 for c in $commits; do
39     git log $c -1
40     echo -n "Try apply? [Y/n] "
41     read answer
42     case $answer in
43         n*)
44             continue
45             ;;
46          *)
47             try_patch $c
48             ;;
49     esac
50 done