rondevera/twig — pull request #16 by ryangreenberg (2013-03-13 06:10:43+00:00)
Title: Provide help even when `twig --help` is not run in a git repository

I ran `twig --help` after installing and got this output:

```
$ workspace twig --help
fatal: Not a git repository (or any of the parent directories): .git
``

I made a small change to `twig` that makes getting help a special case (although this doesn't account for the `twig help` subcommand--maybe you'll have a better idea for how to support this).

A much smaller issue is that twig outputs git's error message when testing for a repository in `Twig#repo?`. I fixed this by redirecting stderr to stdout and added a test.

I had a bit of trouble figuring out how best to test Twig#repo? since it uses the `$?` global. One possibility would be to change Twig.run so it returns an object with both the output and status. Here's a terrible hack solution:

```ruby
require 'forwardable'

class CommandResult < String
extend Forwardable

def_delegators :@process_status, :exited?, :exitstatus, :pid, :signaled?, :stopped?,
:stopsig, :success?, :termsig

attr_accessor :process_status
end

def run(cmd)
result = CommandResult.new(`#{cmd}`)
result.process_status = $?.dup
result
end

result = run("whoami")

puts "result: #{(result).inspect}" # => result: "ryangreenberg\n"
puts "result.success?: #{(result.success?).inspect}" # => result.success?: true
```

This has the nice property of letting callers of `Twig.run` use the return value exactly as if it were the return value of the backtick operator, but with some extra stuff on top. I know, it's messy.

In the meantime, I decided to write a more high-level test that I think describes the expected behavior accurately.

I'm happy to make any changes you'd like--thanks for twig!