|
| 1 | +# amend-commit |
| 2 | + |
| 3 | +A command-line tool that takes the current staged or unstaged changes in the branch and ammends a previously added commit with the changes. |
| 4 | +It preserves commit naming and order. |
| 5 | + |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +With Go installed and `$(go env GOPATH)/bin` on your `PATH`: |
| 10 | + |
| 11 | +``` |
| 12 | +go install github.com/ramzis/amend-commit@latest |
| 13 | +``` |
| 14 | + |
| 15 | +This drops the binary as `amend-commit` into `$(go env GOPATH)/bin`. |
| 16 | + |
| 17 | +Alternatively, clone the repo and use the included Taskfile: |
| 18 | + |
| 19 | +``` |
| 20 | +git clone https://github.com/ramzis/amend-commit.git |
| 21 | +cd amend-commit |
| 22 | +task install |
| 23 | +``` |
| 24 | + |
| 25 | + |
| 26 | +## Usage |
| 27 | +`amend-commit -[number]` |
| 28 | + |
| 29 | +where `number` is an optional flag with a non-negative integer representing the Nth from last commit to amend. |
| 30 | + |
| 31 | +`amend-commit auto` |
| 32 | + |
| 33 | +amends each file in its respective previous commit or logs warning for the files that haven't been commited yet. |
| 34 | + |
| 35 | +## Examples: |
| 36 | + |
| 37 | +- amend-commit |
| 38 | +Amends the last commit. |
| 39 | + |
| 40 | +- amend-commit -1 |
| 41 | +Amends the commit before the last one. |
| 42 | + |
| 43 | +- amend-commit -N |
| 44 | +Amends the Nth commit and so on. |
| 45 | + |
| 46 | +- amend-commit auto |
| 47 | +Amends each file into a previous commit where it was edited. |
| 48 | + |
| 49 | +## Verification |
| 50 | + |
| 51 | +- If using `auto` and a previous commit for that file does not exist, it logs a warning and does not amend it. |
| 52 | +- If a commit is from the base branch, it logs a warning and does not amend it. |
| 53 | +- If a commit amends files that were edited it other commits on this branch, it logs a warning and does not amend it. |
| 54 | + This enforces the convention that each commit in a feature branch modifies a file once. |
| 55 | + |
| 56 | +## Tests |
| 57 | +The tool includes a Go test suite that runs the command line tool with various branch states and checks the correct behaviour. |
| 58 | + |
| 59 | +Example test case: |
| 60 | + |
| 61 | +Commit history (latest is first): |
| 62 | +COMMIT A (changes to files: A) |
| 63 | +COMMIT B (changes to files: B) |
| 64 | + |
| 65 | +- Changes: Add line to file A. |
| 66 | +- Run `amend-commit`. Expected: changes applied to commit A since it previously edited file A. |
| 67 | +- Run `amend-commit -1`. Expected: no changes, warning since another commit on the branch (commit A) already touched the same file. |
| 68 | +- Changes: Add line to file B. |
| 69 | +- Run `amend-commit`. Expected: no changes, warning since another commit on the branch (commit B) already touched the same file. |
| 70 | +- Run `amend-commit -1`. Expected: changes applied to commit B since it previously edited file B. |
| 71 | + |
| 72 | + |
| 73 | +Example test case using auto: |
| 74 | + |
| 75 | +Commit history (latest is first): |
| 76 | +COMMIT A (changes to files: A) |
| 77 | +COMMIT B (changes to files: B) |
| 78 | + |
| 79 | +- Changes: Add line to file A. |
| 80 | +- Changes: Add line to file B. |
| 81 | +- Changes: Add line to file C. |
| 82 | +- Changes: Add line to file D. |
| 83 | +- Run `amend-commit auto`. Expected: commit A gets changes for file A. commit B gets changes for file B. a warning is logged for file C, D. |
0 commit comments