@@ -162,6 +162,33 @@ func stageChanges() {
162162 getThePluginDir ())
163163}
164164
165+ // Checks out the master branch in the plugin repo as long as the repo is clean
166+ func checkoutMasterBranch () {
167+ // Open the repo so we can make changes to it
168+ repo , err := git .PlainOpen (getThePluginDir ())
169+ check (err )
170+
171+ // Open the worktree
172+ workTree , err := repo .Worktree ()
173+ check (err )
174+
175+ // Check if repo is dirty
176+ workTreeStatus , err := workTree .Status ()
177+ if ! workTreeStatus .IsClean () {
178+ fmt .Printf ("%s is dirty.\n " , getThePluginDir ())
179+ fmt .Println ("Please commit or stash your changes." )
180+ return
181+ }
182+
183+ // Checkout the new branch
184+ err = workTree .Checkout (& git.CheckoutOptions {Branch : "refs/heads/master" })
185+ check (err )
186+
187+ if err == nil {
188+ fmt .Println ("Checked out master branch." )
189+ }
190+ }
191+
165192// Updates the plugin version number based on input level
166193// `level` can be: major, minor or patch
167194// It only changes version number in package.json by default.
@@ -305,6 +332,15 @@ func main() {
305332 return
306333 },
307334 },
335+ {
336+ Name : "checkout-master" ,
337+ Aliases : []string {"cm" },
338+ Usage : "Checkout master branch in plugin repo" ,
339+ Action : func (c * cli.Context ) (err error ) {
340+ checkoutMasterBranch ()
341+ return
342+ },
343+ },
308344 {
309345 Name : "setup" ,
310346 Usage : "Setup needed dirs and stuff for dc-plugged" ,
0 commit comments