diff --git a/create_challenge.sh b/create_challenge.sh index edf0ee0..bcf1512 100755 --- a/create_challenge.sh +++ b/create_challenge.sh @@ -50,9 +50,27 @@ replace_placeholders "$DOCDIR/03_commit/commit.md" > commit.md git add commit.md commit -m "Add description on commit" -git switch --detach @ -# TODO: create interactive rebase commit -INTERACTIVE_REBASE_COMMIT="INTERACTIVE_REBASE_COMMIT" +git switch --detach main +printf "%s" '# Interactive rebase + +An interactive rebase lets you (as the name suggests) interact with it instead of just step by step applying each patch. This can be incredibly useful after you created a lot of `git commit -m "WIP: Coffee break"`' > interactive-rebase.md +git add interactive-rebase.md +commit -m "WIP: Coffee break" +echo " commits, but after you are done with your feature, you don't want keep them forever and you don't want to bother the reviewer (and you yourself when you will eventually try to find a bug in your code and look at the log) with them." >> interactive-rebase.md +git add interactive-rebase.md +commit -m "WIP: finish sentence on interactive rebases" +INTERACTIVE_REBASE_EXAMPLE_PICKS="$(git log --oneline main..@ | sed 's/^/pick /' | sed 's/$/\\/g') +[...]" +# FIXME +INTERACTIVE_REBASE_BASE_COMMIT="$(git rev-parse --short main)" +replace_placeholders "$DOCDIR/07_rebase_merge/interactive-rebase-continued.md" >> interactive-rebase.md +git add interactive-rebase.md +commit -m "Finish describing interactive rebases + +TODO: squash commits..." +INTERACTIVE_REBASE_COMMIT="$(git rev-parse --short @)" + +git switch --detach main replace_placeholders "$DOCDIR/07_rebase_merge/combine_history.md" > combine_history.md git add combine_history.md commit -m "Add description on how to combine branches" diff --git a/src/07_rebase_merge/interactive-rebase-continued.md b/src/07_rebase_merge/interactive-rebase-continued.md new file mode 100644 index 0000000..e7c7106 --- /dev/null +++ b/src/07_rebase_merge/interactive-rebase-continued.md @@ -0,0 +1,15 @@ +When you run +```sh +git rebase -i INTERACTIVE_REBASE_BASE_COMMIT +``` +(or `--interactive`), an editor will open, showing a list of all the commits that would be applied. + +CAREFUL: in contrast to the output of `git log` where the newest commit is at the top, in this list the last commit is at the bottom! + +The output starts with a block of lines that look like this: +``` +INTERACTIVE_REBASE_EXAMPLE_PICKS +``` +But what does this mean? Fortunately at the bottom of the file it shows a short summary on all the possible commands. + + diff --git a/src/07_rebase_merge/interactive-rebase-sequence-editor.sh b/src/07_rebase_merge/interactive-rebase-sequence-editor.sh new file mode 100755 index 0000000..b419c16 --- /dev/null +++ b/src/07_rebase_merge/interactive-rebase-sequence-editor.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Mac sed has a different format for -i, so manually replace that file +# hack: just replace "pick" with "fixup" until line 1000 (which does not exist), but I can't be bothered to find a nicer way not to change the first line... +sed '2,1000s/^pick/fixup/' < "$1" > "$1.bak" +# output the file for grabbing the flag +cat "$1.bak" +mv "$1.bak" "$1" diff --git a/src/hooks/pre-rebase b/src/hooks/pre-rebase new file mode 100755 index 0000000..584a5d2 --- /dev/null +++ b/src/hooks/pre-rebase @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 'Flag: ItsAllAboutTheRebase' diff --git a/test.sh b/test.sh index f69ad63..28c106c 100755 --- a/test.sh +++ b/test.sh @@ -58,8 +58,13 @@ expect "git show the-first-tag" to contain "Flag: AnnotateMeIfYouCan" git switch --detach -q the-first-tag ' -xit 'TODO: find title for combine_history testcase' <&1' to contain "Flag: ItsAllAboutTheRebase" +EOF + +it 'interactive rebase succeeds' </dev/null 2>&1 EOF echo success!