diff options
| author | Teddy Wing | 2014-12-06 18:16:28 -0500 | 
|---|---|---|
| committer | Teddy Wing | 2014-12-06 18:16:28 -0500 | 
| commit | fe9abe49b3b9e9c325d8cb73728fdde119e8c79b (patch) | |
| tree | 11bd6e0bd2b7637e7a0e005e774bf449ac38da21 | |
| parent | 4751d4f5641137fba7c6848813a456640927ed85 (diff) | |
| download | git-checkout-history-fe9abe49b3b9e9c325d8cb73728fdde119e8c79b.tar.bz2 | |
git-checkout-history: Passing an arg checks out a branch
If you pass in the index of a branch in the checkout-history branch
list, the branch at that index in the history will be checked out.
TODO: Store the newly checked out branch in the branch history
| -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]) +		}  	}  } | 
