|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# git-absorb binary path |
| 4 | +if [ $# -eq 0 ]; then |
| 5 | + GIT_ABSORB_BIN="git absorb" |
| 6 | +else |
| 7 | + GIT_ABSORB_BIN=$1 |
| 8 | +fi |
| 9 | + |
| 10 | + |
| 11 | +README_FILE=README.md |
| 12 | +GIT_ANNOTATED_TAG="annotated-tag" |
| 13 | + |
| 14 | +# initialize a git repository |
| 15 | +git init |
| 16 | + |
| 17 | +# commit 1: create a sample file |
| 18 | +touch ${README_FILE} |
| 19 | +# commit 1: stage change |
| 20 | +git add ${README_FILE} |
| 21 | +# commit 1: create initial commit |
| 22 | +git commit -m 'Initial commit' |
| 23 | + |
| 24 | +# commit 2: update file |
| 25 | +cat <<EOF >| ${README_FILE} |
| 26 | +# readme |
| 27 | +
|
| 28 | +Testing |
| 29 | +
|
| 30 | +## header 2: part 1 |
| 31 | +
|
| 32 | +Header 2 testing. part 1 |
| 33 | +
|
| 34 | +## header 2: part 2 |
| 35 | +
|
| 36 | +Header 2 testing. part 2 |
| 37 | +EOF |
| 38 | +# commit 2: stage updates |
| 39 | +git add ${README_FILE} |
| 40 | +# commit 2: create commit |
| 41 | +git commit -m 'Update readme' |
| 42 | + |
| 43 | +# commit 2: make this commit as annotated commit |
| 44 | +git tag -a ${GIT_ANNOTATED_TAG} -m 'my annotated tag' |
| 45 | + |
| 46 | +# commit 3: insert lines in the middle |
| 47 | +ed ${README_FILE} <<< '9i |
| 48 | +### header 3: part 1 |
| 49 | +
|
| 50 | +this is header 3 |
| 51 | +
|
| 52 | +. |
| 53 | +w |
| 54 | +q |
| 55 | +' |
| 56 | +# commit 3: stage changes |
| 57 | +git add ${README_FILE} |
| 58 | +# commit 3: create commit |
| 59 | +git commit -m 'More updates' |
| 60 | + |
| 61 | +# commit 4: insert additional lines |
| 62 | +ed ${README_FILE} <<< '7d |
| 63 | +7i |
| 64 | +Header 2 testing. |
| 65 | +
|
| 66 | +foo |
| 67 | +
|
| 68 | +part 1 |
| 69 | +. |
| 70 | +w |
| 71 | +q' |
| 72 | +# commit 4: stage changes |
| 73 | +git add ${README_FILE} |
| 74 | +# commit 4: create commit |
| 75 | +git commit -m 'Commute commit' |
| 76 | + |
| 77 | +# commit 5: create the diff that'll commute |
| 78 | +ed ${README_FILE} <<< '9d |
| 79 | +9i |
| 80 | +foobar |
| 81 | +. |
| 82 | +w |
| 83 | +q' |
| 84 | +# commit 5: stage change |
| 85 | +git add -u ${README_FILE} |
| 86 | +# commit 5: try to absorb |
| 87 | +${GIT_ABSORB_BIN} -v --base ${GIT_ANNOTATED_TAG} |
0 commit comments