-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repair
stg repair
with amended first patch
When `stg repair` searches for commits to "patchify", it looks for commits that are children of known patch commits. This left an unhandled edge case where if only one patch was applied, and that patch was amended with `git commit --amend`, the amended commit would not be patchified and, worse, that commit would become orphaned. `stg repair` is modified to look for the last known stack base commit in addition to known patch commits such that children of the base commit will now be patchified. An added benefit of identifying the stack's base commit is that it signals the point beyond which no patches will be found and thus allows searching to stop and a potentially large amount of work avoided. This can have a significant impact on the performance of running `stg repair` in a repositories with long histories. Repairs #163 Signed-off-by: Peter Grayson <pete@jpgrayson.net>
- Loading branch information
Showing
2 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/sh | ||
test_description='Test "stg repair" of amended commits' | ||
. ./test-lib.sh | ||
|
||
test_expect_success 'Initialize the StGit patch' ' | ||
stg init && | ||
echo "hello" > foo.txt && | ||
stg add foo.txt && | ||
stg new -m p0 && | ||
stg refresh | ||
' | ||
|
||
test_expect_success 'Amend patch commit with git' ' | ||
echo "amended" >> foo.txt && | ||
git commit -a --amend -m "p0 amended" | ||
' | ||
|
||
test_expect_success 'Repair amended patch' ' | ||
stg repair && | ||
test "$(echo $(stg series --noprefix --applied))" = "p0-amended" && | ||
test "$(echo $(stg series --noprefix --unapplied))" = "p0" && | ||
test "$(tail -n1 foo.txt)" = "amended" | ||
' | ||
|
||
test_expect_success 'Reset to original patch' ' | ||
stg delete p0-amended && | ||
stg push p0 | ||
' | ||
|
||
test_expect_success 'Add more applied and unapplied patches' ' | ||
stg new -m p1 && | ||
echo "from p1" >> foo.txt && | ||
stg refresh && | ||
stg new -m p2 && | ||
echo "from p2" >> foo.txt && | ||
stg refresh && | ||
stg pop p2 && | ||
test "$(echo $(stg series --noprefix --applied))" = "p0 p1" && | ||
test "$(echo $(stg series --noprefix --unapplied))" = "p2" | ||
' | ||
|
||
test_expect_success 'Amend middle patch' ' | ||
echo "p1 amended" >> foo.txt && | ||
git commit -a --amend -m "p1 amended" | ||
' | ||
|
||
test_expect_success 'Repair amended middle patch' ' | ||
stg repair && | ||
test "$(echo $(stg series --noprefix --applied))" = "p0 p1-amended" && | ||
test "$(echo $(stg series --noprefix --unapplied))" = "p1 p2" && | ||
test "$(tail -n1 foo.txt)" = "p1 amended" | ||
' | ||
|
||
test_expect_success 'Reset to non-amended patches' ' | ||
stg delete p1-amended && | ||
stg pop -a | ||
' | ||
|
||
test_expect_success 'Add commit onto stack base' ' | ||
echo "new commit" > foo.txt && | ||
git add foo.txt && | ||
git commit -m "add foo" | ||
' | ||
|
||
test_expect_success 'Repair new commit on stack base' ' | ||
stg repair && | ||
test "$(echo $(stg series --noprefix --applied))" = "" && | ||
test "$(echo $(stg series --noprefix --unapplied))" = "p0 p1 p2" && | ||
test "$(tail -n1 foo.txt)" = "new commit" | ||
' | ||
|
||
test_done |