66 "strings"
77)
88
9+ // command executes a command with a bunch of options
10+ // It uses a Cmd to run the command with the right context and the correct Executor that can be swapped for
11+ // testing purposes.
912func command (ctx context.Context , name string , options ... types.Option ) (string , error ) {
1013 g := types .NewCmd (name )
1114 g .AddOptions (options ... )
@@ -14,30 +17,41 @@ func command(ctx context.Context, name string, options ...types.Option) (string,
1417 return strings .TrimSpace (res ), err
1518}
1619
20+ // SetExecutor is the way to substitute the default execution model for testing purposes
1721func SetExecutor (executor types.Executor ) types.Option {
1822 return func (g * types.Cmd ) {
1923 g .Executor = executor
2024 }
2125}
2226
27+ // SetDebug is there to activate debugging for command executions
2328func SetDebug (debug bool ) types.Option {
2429 return func (g * types.Cmd ) {
2530 g .Debug = debug
2631 }
2732}
2833
34+ // Config sets up a `git config` cli command
2935func Config (options ... types.Option ) (string , error ) {
3036 return command (context .Background (), "config" , options ... )
3137}
38+
39+ // DiffIndex sets up a `git diff-index` cli command
3240func DiffIndex (options ... types.Option ) (string , error ) {
3341 return command (context .Background (), "diff-index" , options ... )
3442}
43+
44+ // DiffTree sets up a `git diff-tree` cli command
3545func DiffTree (options ... types.Option ) (string , error ) {
3646 return command (context .Background (), "diff-tree" , options ... )
3747}
48+
49+ // Log sets up a `git log` command
3850func Log (options ... types.Option ) (string , error ) {
3951 return command (context .Background (), "log" , options ... )
4052}
53+
54+ // RevParse sets up a `git rev-parse` cli command
4155func RevParse (options ... types.Option ) (string , error ) {
4256 return command (context .Background (), "rev-parse" , options ... )
4357}
0 commit comments