Git-TCRDD

TCRDD = TCR (test && commit || revert) + TDD (Test Driven Development)

Original idea by Xavier Detant

pipeline status

Theory

TCR

TCR is cool! It encourages doing baby steps, reducing the waste when we are wrong

But it doesn't allow us to see the tests failing

So:

TDD

TDD is cool! It makes sure we develop the right thing, step by step

TCRDD

TCRDD = TCR + TDD

TCRDD blends the constraints of the two methods to benefit from their advantages

Therefore, TCRDD makes sure we develop the right thing, step by step, and we are encouraged to do so by baby steps, reducing the waste when we are wrong

```plantuml @startuml skinparam ArrowColor black

start repeat partition "red" #Coral { repeat :Write a test] :Gamble that the tests fail/ if (Actually run tests) then (Fail) -[#Red]-> :Commit; break else (Pass) -[#Green]-> :Revert; endif repeat while (Write another test) } partition "green" #Lime { repeat :Write the minimum code] :Gamble that the tests pass/ if (Actually run tests) then (Pass) -[#Green]-> :Commit; break else (Fail) -[#Red]-> :Revert; endif repeat while (Try something else) } partition "refactor" #668cff { repeat repeat :Write code without changing the behavior] :Gamble that the tests pass/ if (Actually run tests) then (Pass) -[#Green]-> :Commit; break else (Fail) -[#Tomato]-> :Revert; endif repeat while (Change something else) repeat while (Another things to refactor ?) } repeat while (Another feature to add ?) stop @enduml ```

How to install

This will be improved

Install Git and ensure that is availlable in your $PATH

Install Cargo

```sh

Clone this project

git clone git@gitlab.com:pinage404/git-tcrdd.git

Move to the cloned repository

cd git-tcrdd

Build the executable

cargo build --release ```

Add the build stuff to your $PATH

Fish:

fish set --export --append PATH $PWD/target/release

Bash / ZSH:

bash export PATH=$PATH:$PWD/target/release

Check if all have been well settled

sh git tcrdd

If it has been well settled, it should output this :

error: The following required arguments were not provided:
    <test-command>...
    <--pass|--fail>

USAGE:
    git-tcrdd --repository-path <repository-path> <--pass|--fail>

For more information try --help

If it has been badly settled, it should output this :

git : 'tcrdd' is not a git command. See 'git --help'.

How to use

```sh

To see all available flags and options

git-tcrdd --help

Write a failing test in your codebase

Then

git tcrdd --fail -- $YOURTESTCOMMAND

Write the minimum code to make tests pass

Then

git tcrdd --pass -- $YOURTESTCOMMAND

Refactor your code

Then

git tcrdd --pass -- $YOURTESTCOMMAND

It's a bit tedious to always repeat the test command

So you can set an environment variable with the test command to avoid repeating it all the time

export TCRDDTESTCOMMAND="sh -c 'cargo fmt ; cargo clippy --all-targets ; cargo check --all-targets ; cargo test'" git tcrdd --pass ```

Test command must exit with a 0 status when there are 0 failing tests, anything else is considered as a failure

Backlog

plantuml @startmindmap "backlog" * Backlog left side * Done * MVP * base * run tests * `git commit` * `git revert` * test it * TCR * option --pass * TRC * option --fail * give path in option * improve test command * test command with arguments * script * dry run flag * help option * -h * --help * exclusive flag * required flag * option colors * -g * --green * -r * --red * merge commits * `git update-ref` * `git commit --amend` * should fail without test command * test command from envirronement variable * display when committed or reverted * how to use * test in isolated and reproductible envirronement * container * CI * [[https://doc.rust-lang.org/cargo/guide/continuous-integration.html Cargo's Documentation about CI]] * choose a licence * complete metadata * WIP * publish it ? * [[https://doc.rust-lang.org/cargo/reference/publishing.html publishing]] right side * TODO * how to install * when revert `git clean` * message option * -m * --message * amend should keep message * `"--reuse-message=@",` * shell completion * tcrdd hooks * branch based developement * `git commit --fixup` * `git rebase --autosquash` * trunk based developement * `git pull` * `git push` * rename project? * simpler to say and understand and remember when not familiar with `TCR` or `TDD` * from `git-tcrdd` to `git-...`? * [[https://www.wordreference.com/fren/jouer jouer?]] * [[https://www.wordreference.com/fren/parier parier?]] * [[https://www.wordreference.com/enfr/bet bet?]] * [[https://www.wordreference.com/enfr/expect expect?]] * [[https://www.wordreference.com/enfr/gamble gamble?]] * [[https://www.wordreference.com/enfr/should should?]] * like git, flags & options & arguments should be retrieved from CLI or environment variable or config's file * re-use `git config` to store in file ? * OS distribution * [[https://crates.io/crates/crate2nix crate2nix]] * [[https://crates.io/crates/cargo-deb cargo-deb]] * [[https://crates.io/crates/cargo-rpm cargo-rpm]] @endmindmap

Reinvent the wheel

Why reinvent the wheel?

This script already works well

Because i would like to learn Rust ¯\_(ツ)_/¯