John L. Villalovos | d22378d | 2017-08-01 14:47:54 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -u |
| 4 | set -e |
| 5 | # set -x |
| 6 | |
| 7 | BASE_DIR=$(cd $(dirname $0)/.. && pwd) |
| 8 | IRONIC_DIR=$(cd ${BASE_DIR}/../ironic && pwd) |
| 9 | |
| 10 | BACKUP_DIR=${BASE_DIR}/copy-ironic_tempest_plugin/ |
| 11 | TEMPEST_PLUGIN_DIR=${IRONIC_DIR}/ironic_tempest_plugin/ |
| 12 | NEW_PLUGIN_DIR=${BASE_DIR}/ironic_tempest_plugin/ |
| 13 | |
| 14 | echo "openstack/ironic-tempest-plugin repository location: $BASE_DIR" |
| 15 | echo "openstack/ironic repository location: $IRONIC_DIR" |
| 16 | echo |
| 17 | |
| 18 | if [[ ! -d ${IRONIC_DIR}/.git/ ]]; then |
| 19 | echo "Error: The openstack/ironic git repository is not present at: ${IRONIC_DIR}" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | cd ${IRONIC_DIR} |
| 24 | |
| 25 | # Try to sync our repository to master |
| 26 | echo "Syncing ${IRONIC_DIR} to origin/master branch..." |
| 27 | git remote update && git reset --hard origin/master -- && git checkout -f master && git pull origin master |
| 28 | |
| 29 | echo |
| 30 | echo "Erase all non git tracked files..." |
| 31 | git clean -f -x -d |
| 32 | |
| 33 | echo |
| 34 | echo "Make backup copy of original ironic_tempest_plugin/ directory ..." |
| 35 | rsync -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 | |
| 49 | echo |
| 50 | echo "Remove everything except ironic_tempest_plugin/ ..." |
| 51 | git 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 | |
| 57 | echo |
| 58 | echo "Remove empty merge commits..." |
| 59 | git filter-branch -f --prune-empty --parent-filter \ |
| 60 | 'sed "s/-p //g" | xargs -r git show-branch --independent | sed "s/\</-p /g"' |
| 61 | |
| 62 | echo |
| 63 | echo "Remove all the merge commits..." |
| 64 | for commit in $(git rev-list --merges master); do |
| 65 | echo "Removing merge commit: ${commit}" |
| 66 | git rebase --committer-date-is-author-date ${commit}^ |
| 67 | done |
| 68 | |
| 69 | echo |
| 70 | echo "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. |
| 74 | git 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 | |
| 80 | echo |
| 81 | echo "Comparing content from backup copy with new processed copy..." |
| 82 | echo "Comparing backup dir: ${BACKUP_DIR}" |
| 83 | echo "To new ironic-tempest-plugin dir: ${TEMPEST_PLUGIN_DIR}" |
| 84 | echo "We should have no output" |
| 85 | diff -Naur ${TEMPEST_PLUGIN_DIR} ${BACKUP_DIR} |
| 86 | |
| 87 | echo "No differences. Yay! :)" |
| 88 | |
| 89 | # Get all but the very first commit |
| 90 | REV_LIST=$(git rev-list master | head -n -1 | tac) |
| 91 | |
| 92 | cd ${BASE_DIR} |
| 93 | |
| 94 | # Determine the commit ID for our newest commit |
| 95 | CURRENT_REV=$(git show --no-patch --pretty=format:"%H") |
| 96 | |
| 97 | echo -e "\n\n" |
| 98 | echo "Press <Enter> if you want to cherry-pick the commits into your repository at:" |
| 99 | echo "${BASE_DIR}" |
| 100 | echo |
| 101 | echo "Otherwise press <CTRL>-C to abort..." |
| 102 | read |
| 103 | |
| 104 | echo "Cherry picking commits..." |
| 105 | sleep 1.0 |
| 106 | git remote add ironic-$$ ${IRONIC_DIR}/.git |
| 107 | git fetch ironic-$$ |
| 108 | for 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 |
| 116 | done |
| 117 | git remote remove ironic-$$ |
| 118 | |
| 119 | echo "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. |
| 123 | git 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 | |
| 131 | echo "Comparing content from backup copy with new cherry-picked version..." |
| 132 | echo "Comparing backup dir: ${BACKUP_DIR}" |
| 133 | echo "To cherry-picked ironic-tempest-plugin dir: ${NEW_PLUGIN_DIR}" |
| 134 | echo "We should have no output" |
| 135 | diff -Naur ${TEMPEST_PLUGIN_DIR} ${NEW_PLUGIN_DIR} |
| 136 | |
| 137 | echo "No differences. Yay! :)" |
| 138 | echo "Success. We are done!" |