blob: 9671ff96a23ae60293fd93c34a1e56361998fab4 [file] [log] [blame]
John L. Villalovosd22378d2017-08-01 14:47:54 -07001#!/bin/bash
2
3set -u
4set -e
5# set -x
6
7BASE_DIR=$(cd $(dirname $0)/.. && pwd)
8IRONIC_DIR=$(cd ${BASE_DIR}/../ironic && pwd)
9
10BACKUP_DIR=${BASE_DIR}/copy-ironic_tempest_plugin/
11TEMPEST_PLUGIN_DIR=${IRONIC_DIR}/ironic_tempest_plugin/
12NEW_PLUGIN_DIR=${BASE_DIR}/ironic_tempest_plugin/
13
14echo "openstack/ironic-tempest-plugin repository location: $BASE_DIR"
15echo "openstack/ironic repository location: $IRONIC_DIR"
16echo
17
18if [[ ! -d ${IRONIC_DIR}/.git/ ]]; then
19 echo "Error: The openstack/ironic git repository is not present at: ${IRONIC_DIR}"
20 exit 1
21fi
22
23cd ${IRONIC_DIR}
24
25# Try to sync our repository to master
26echo "Syncing ${IRONIC_DIR} to origin/master branch..."
27git remote update && git reset --hard origin/master -- && git checkout -f master && git pull origin master
28
29echo
30echo "Erase all non git tracked files..."
31git clean -f -x -d
32
33echo
34echo "Make backup copy of original ironic_tempest_plugin/ directory ..."
35rsync -aH --delete ${TEMPEST_PLUGIN_DIR} ${BACKUP_DIR}
36
37# Examples of the variables exported by '--index-filter'
38# GIT_AUTHOR_DATE=@1275026726 -0700
39# GIT_AUTHOR_EMAIL=anotherjesse@gmail.com
40# GIT_AUTHOR_NAME=Jesse Andrews
41# GIT_COMMIT=07d272b2aad660682dc59f1ff038adeb10481210
42# GIT_COMMITTER_DATE=@1275026726 -0700
43# GIT_COMMITTER_EMAIL=anotherjesse@gmail.com
44# GIT_COMMITTER_NAME=Jesse Andrews
45# GIT_DIR=/home/jdoe/openstack/ironic/.git
46# GIT_INDEX_FILE=/home/jdoe/openstack/ironic/.git-rewrite/t/../index
47# GIT_WORK_TREE=.
48
49echo
50echo "Remove everything except ironic_tempest_plugin/ ..."
51git filter-branch -f --prune-empty \
52 --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- ironic_tempest_plugin' \
53 --prune-empty \
54 --tag-name-filter cat
55
56
57echo
58echo "Remove empty merge commits..."
59git filter-branch -f --prune-empty --parent-filter \
60 'sed "s/-p //g" | xargs -r git show-branch --independent | sed "s/\</-p /g"'
61
62echo
63echo "Remove all the merge commits..."
64for commit in $(git rev-list --merges master); do
65 echo "Removing merge commit: ${commit}"
66 git rebase --committer-date-is-author-date ${commit}^
67done
68
69echo
70echo "Make the committer be the same as the author..."
71# There are a few cases where the committer and the author are not the same.
72# But if we don't do this then every patch will have the committer be the
73# person running this script.
74git filter-branch -f --env-filter '
75 export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
76 export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
77 export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
78' --tag-name-filter cat
79
80echo
81echo "Comparing content from backup copy with new processed copy..."
82echo "Comparing backup dir: ${BACKUP_DIR}"
83echo "To new ironic-tempest-plugin dir: ${TEMPEST_PLUGIN_DIR}"
84echo "We should have no output"
85diff -Naur ${TEMPEST_PLUGIN_DIR} ${BACKUP_DIR}
86
87echo "No differences. Yay! :)"
88
89# Get all but the very first commit
90REV_LIST=$(git rev-list master | head -n -1 | tac)
91
92cd ${BASE_DIR}
93
94# Determine the commit ID for our newest commit
95CURRENT_REV=$(git show --no-patch --pretty=format:"%H")
96
97echo -e "\n\n"
98echo "Press <Enter> if you want to cherry-pick the commits into your repository at:"
99echo "${BASE_DIR}"
100echo
101echo "Otherwise press <CTRL>-C to abort..."
102read
103
104echo "Cherry picking commits..."
105sleep 1.0
106git remote add ironic-$$ ${IRONIC_DIR}/.git
107git fetch ironic-$$
108for revision in ${REV_LIST}; do
109 # NOTE(jlvillal): The cherry-pick will change the CommitAuthor and
110 # CommitDate. I tried to setting the variables:
111 # GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
112 # GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
113 # GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
114 # With no success in changing this behavior
115 git cherry-pick $revision
116done
117git remote remove ironic-$$
118
119echo "Make the committer be the same as the author..."
120# There are a few cases where the committer and the author are not the same.
121# But if we don't do this then every patch will have the committer be the
122# person running this script.
123git filter-branch -f --env-filter '
124 export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
125 export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
126 export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
127' --tag-name-filter cat ${CURRENT_REV}..HEAD
128# We make sure to not modify any commits that were already in this repository
129# before.
130
131echo "Comparing content from backup copy with new cherry-picked version..."
132echo "Comparing backup dir: ${BACKUP_DIR}"
133echo "To cherry-picked ironic-tempest-plugin dir: ${NEW_PLUGIN_DIR}"
134echo "We should have no output"
135diff -Naur ${TEMPEST_PLUGIN_DIR} ${NEW_PLUGIN_DIR}
136
137echo "No differences. Yay! :)"
138echo "Success. We are done!"