Skip to content

Commit

Permalink
WIP interactive rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
miallo committed Jan 7, 2024
1 parent 0c3b59e commit 5e0628a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
24 changes: 21 additions & 3 deletions create_challenge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,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=INTERACTIVE_REBASE_BASE_COMMIT
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"
Expand Down
15 changes: 15 additions & 0 deletions src/07_rebase_merge/interactive-rebase-continued.md
Original file line number Diff line number Diff line change
@@ -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.


8 changes: 8 additions & 0 deletions src/07_rebase_merge/interactive-rebase-sequence-editor.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions src/hooks/pre-rebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo 'nuggit: ItsAllAboutTheRebase'
1 change: 1 addition & 0 deletions src/nuggits
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ShowMeMore
MyFirstBranch
LogCat
AnnotateMeIfYouCan
ItsAllAboutTheRebase
10 changes: 8 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ redeem_nuggit AnnotateMeIfYouCan
git switch --detach -q the-first-tag
'

xit 'TODO: find title for combine_history testcase' <<EOF
expect 'eval "\$(get_sh_codeblock combine_history.md)"' to contain "FIXME TODO"
it 'ItsAllAboutTheRebase shown in rebase' <<EOF
# do a rebase
expect 'eval "\$(get_sh_codeblock combine_history.md)" 2>&1' to contain "nuggit: ItsAllAboutTheRebase"
redeem_nuggit ItsAllAboutTheRebase
EOF

xit 'interactive rebase succeeds' <<EOF
GIT_SEQUENCE_EDITOR="$DOCDIR/07_rebase_merge/interactive-rebase-sequence-editor.sh" eval "\$(get_sh_codeblock interactive-rebase.md)" >/dev/null
EOF

it 'An invalid nuggit should show an error' '
Expand Down
2 changes: 0 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- hooks (e.g. automatically add flag to commit message)
- post-merge
- post-rewrite e.g. for commit --amend
- pre-rebase
- `--word-diff --word-diff-regex=.` (flag hidden "inbetween" two commits)
- submodule
- `blame` first column
Expand Down Expand Up @@ -68,7 +67,6 @@ See documentation in the git repository under Documentation/githooks.txt
- pre-merge-commit
- commit-msg
- post-commit
- pre-rebase
- post-merge
- pre-push
- pre-receive
Expand Down

0 comments on commit 5e0628a

Please sign in to comment.