Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rebase-Exec] exercise more intuitive #242 #374

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions rebase-exec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@

## Task

Doing local development we've created a bunch of commits. We would like to deliver them all to master. We would also like all commits to pass our tests.

Our test suite is contained in `test.sh`. We can use `git rebase --exec` to run the test suite for all commits. We have tagged the first commit in our history with `initial-commit`.

1. Run the test script using `./test.sh` to see the most recent commit succeed
1. Use `git rebase -i --exec ./test.sh initial-commit` to run the test script on all commits. You will be shown the plan, you do not need to change anything.
1. The tests will run, and fail on a single commit. The tests fail because the test script changes. So you need to fix it
1. Change the following strings in `test.sh`
- `One test failed` to `all tests pass`
- `exit 1` to `exit 0`
1. Stage `test.sh` and use `git commit --amend` to fix the broken commit
1. Run `git rebase --continue` to execute the test suite on the remaining commits
1. You may run `verify.sh` (or `verify.ps1` in PowerShell) to verify your solution
### Example 1:
Adding content to file in last 3 commits using `git rebase -i --exec <command(s)> HEAD~3`.

1. Run `git log --patch` command to see what changes are include in last commit.
2. Run `git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3` command it will open configured editor with information what command will be executed for each commits which is notified by `exec <command>` you can either modify the command or save and exit the editor to let the command run for that specific commit.
3. Run `git log --patch` command to see what are the changes in commits.

### Example 2:
Change the author for all the commits using `git rebase -i --exec`.

1. Run `git log --format="commit: %H%nauthor: %an%n"` command to see detail related to commit and author.
2. Run `git rebase -i --root --exec "git commit --amend --author='my name <[email protected]>' --no-edit"` command it will open configured editor with information what command will be executed for each commits which is notified by `exec <command>` you can either modify the command or save and exit the editor to let the command run for that specific commit.
3. Run `git log --format="commit: %H%nauthor: %an%n"` command to see the changes author information for the commits.

## Useful commands

- `git log --patch`
- `git rebase -i --exec "echo '1' >> 4.txt && git add 4.txt && git commit --amend --no-edit" HEAD~3`
- `git log --format="commit: %H%nauthor: %an%n"`
- `git rebase -i --root --exec "git commit --amend --author='my name <[email protected]>' --no-edit"` or `git rebase -i --exec "git commit --amend --author='my name <[email protected]>' --no-edit" first-commit`
33 changes: 1 addition & 32 deletions rebase-exec/setup.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
. ..\utils\make-exercise-repo.ps1

$testScript = @'
#! /usr/bin/env bash
echo "Running tests on commit $(git rev-parse --short HEAD)"
echo 'all tests pass'
exit 0
'@
Set-Content "test.sh" $testScript

git add 'test.sh'
git commit -m "Initial commit"
git tag initial-commit

Set-Content "1.txt" -Value ""
git add 1.txt
git commit -m "1"
git tag first-commit

Set-Content "2.txt" -Value ""
git add 2.txt
git commit -m "2"

Set-Content "3.txt" -Value ""
git add 3.txt

$testScript = @'
#! /usr/bin/env bash
echo "Running tests on commit $(git rev-parse --short HEAD)"
echo 'One failing test'
exit 1
'@
Set-Content "test.sh" $testScript

git add 'test.sh'
git commit -m "3"

Set-Content "4.txt" -Value ""
Expand All @@ -40,18 +19,8 @@ git commit -m "4"

Set-Content "5.txt" -Value ""
git add 5.txt
$testScript = @'
#! /usr/bin/env bash
echo "Running tests on commit $(git rev-parse --short HEAD)"
echo 'all tests pass'
exit 0
'@
Set-Content "test.sh" $testScript
git add 'test.sh'
git commit -m "5"

Set-Content "6.txt" -Value ""
git add 6.txt
git commit -m "6"


22 changes: 1 addition & 21 deletions rebase-exec/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,17 @@ source ../utils/utils.sh

make-exercise-repo

echo "#! /usr/bin/env bash" > 'test.sh'
echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh'
echo "echo 'all tests pass'" >> 'test.sh'
echo "exit 0" >> 'test.sh'
chmod +x 'test.sh'
git add 'test.sh'
git commit -m "Initial commit"
git tag initial-commit

touch 1.txt
git add 1.txt
git commit -m "1"
git tag first-commit

touch 2.txt
git add 2.txt
git commit -m "2"

touch 3.txt
git add 3.txt
echo "#! /usr/bin/env bash" > 'test.sh'
echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh'
echo "echo 'One failing test'" >> 'test.sh'
echo "exit 1" >> 'test.sh'
git add 'test.sh'
git commit -m "3"

touch 4.txt
Expand All @@ -36,15 +23,8 @@ git commit -m "4"

touch 5.txt
git add 5.txt
echo "#! /usr/bin/env bash" > 'test.sh'
echo 'echo "Running tests on commit $(git rev-parse --short HEAD)"' >> 'test.sh'
echo "echo 'all tests pass'" >> 'test.sh'
echo "exit 0" >> 'test.sh'
git add 'test.sh'
git commit -m "5"

touch 6.txt
git add 6.txt
git commit -m "6"


10 changes: 0 additions & 10 deletions rebase-exec/verify.ps1

This file was deleted.

8 changes: 0 additions & 8 deletions rebase-exec/verify.sh

This file was deleted.