genehack/Git-Wrapper — Issue #8: Request for feature: testing switch
Author: barefootcoder
Created: 2012-02-02 21:12:09+00:00
State: open

How would you feel about a way to have `Git::Wrapper` only print the command it would run, as opposed to actually doing it?

My use case: I'm working on a packaging tool at $work (currently implemented as a moderately thin wrapper around `Dist::Zilla`). At certain points, I want the tool to commit things to git automatically. Naturally, I want my tests to be able to verify that these commits is happening. There are of course a few options for doing this:

1. Create a fake repo, do any commits there, clean it up afterwards. (I note that this is how `Git::Wrapper` itself is tested.) This doesn't work that well for me for a few reasons.
1. Go ahead and do the commit and just remove the commit afterwards. This is how I'm currently doing it now, and it works, but it just seems ... dangerous. Plus, for safety's sake, I'm doing a `git stash` to make sure I don't blow anything away I can't get back, which means that every time I run my test suite, I end up littering my repo with stashes.
1. Add something to `Git::Wrapper` that says, you know what, in this instance, don't really do the commit, just tell me what git command you're about to run (print it to STDERR or somesuch) and then I can check for that message and feel confident that the commit really would have taken place.

Obviously I'm angling for option # 3 here. :-)

Assuming you _are_ amenable to such an option, what would be your preference for how to activate it? I see, again, 3 decent options:

1. subclass (e.g. `Test::Git::Wrapper`) [not my favorite--most intrusive]
2. package var (e.g. `$Git::Wrapper::TEST_MODE = 1`)
3. environment var (e.g. `$ENV{GIT_WRAPPER_TEST_MODE} = 1`) [least intrusive]

If this sounds good to you, pick an option and let me know and I'll put together a pull request. From looking at the `_cmd` method, it should be pretty easy.