diff options
| -rw-r--r-- | git-checkout-history/main.go | 19 | 
1 files changed, 17 insertions, 2 deletions
| diff --git a/git-checkout-history/main.go b/git-checkout-history/main.go index fa9747c..8bf6e24 100644 --- a/git-checkout-history/main.go +++ b/git-checkout-history/main.go @@ -4,7 +4,10 @@ import (  	"fmt"  	"io/ioutil"  	"log" +	"os" +	"os/exec"  	"os/user" +	"strconv"  	"gopkg.in/yaml.v2"  ) @@ -37,7 +40,19 @@ func main() {  		log.Fatal(err)  	} -	for i := 1; i < len(branchList.Branches); i++ { -		fmt.Printf("[%d] %s\n", i, branchList.Branches[i]) +	args := os.Args[1:] +	 +	if len(args) > 0 { +		branchIndex, _ := strconv.Atoi(args[0]) +		cmd := exec.Command("git", "checkout", branchList.Branches[branchIndex]) +		err := cmd.Run() +		if err != nil { +			fmt.Fprintf(os.Stderr, err.Error()) +		} +	} else { +		// List branches in history +		for i := 1; i < len(branchList.Branches); i++ { +			fmt.Printf("[%d] %s\n", i, branchList.Branches[i]) +		}  	}  } | 
