forked from toolshed/abra
		
	refactor: less quotes
This commit is contained in:
		| @ -15,10 +15,10 @@ import ( | ||||
| // Clone runs a git clone which accounts for different default branches. | ||||
| func Clone(dir, url string) error { | ||||
| 	if _, err := os.Stat(dir); os.IsNotExist(err) { | ||||
| 		logrus.Debugf("'%s' does not exist, attempting to git clone from '%s'", dir, url) | ||||
| 		logrus.Debugf("%s does not exist, attempting to git clone from %s", dir, url) | ||||
| 		_, err := git.PlainClone(dir, false, &git.CloneOptions{URL: url, Tags: git.AllTags}) | ||||
| 		if err != nil { | ||||
| 			logrus.Debugf("cloning '%s' default branch failed, attempting from main branch", url) | ||||
| 			logrus.Debugf("cloning %s default branch failed, attempting from main branch", url) | ||||
| 			_, err := git.PlainClone(dir, false, &git.CloneOptions{ | ||||
| 				URL:           url, | ||||
| 				Tags:          git.AllTags, | ||||
| @ -32,9 +32,9 @@ func Clone(dir, url string) error { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 		logrus.Debugf("'%s' has been git cloned successfully", dir) | ||||
| 		logrus.Debugf("%s has been git cloned successfully", dir) | ||||
| 	} else { | ||||
| 		logrus.Debugf("'%s' already exists, doing nothing", dir) | ||||
| 		logrus.Debugf("%s already exists, doing nothing", dir) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @ -54,37 +54,32 @@ func EnsureUpToDate(dir string) error { | ||||
| 	} | ||||
|  | ||||
| 	if !isClean { | ||||
| 		return fmt.Errorf("'%s' has locally unstaged changes", recipeName) | ||||
| 		return fmt.Errorf("%s has locally unstaged changes", recipeName) | ||||
| 	} | ||||
|  | ||||
| 	branch := "master" | ||||
| 	if _, err := repo.Branch("master"); err != nil { | ||||
| 		if _, err := repo.Branch("main"); err != nil { | ||||
| 			logrus.Debugf("failed to select branch in '%s'", dir) | ||||
| 			return err | ||||
| 		} | ||||
| 		branch = "main" | ||||
| 	branch, err := GetCurrentBranch(repo) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	logrus.Debugf("choosing '%s' as main git branch in '%s'", branch, dir) | ||||
| 	logrus.Debugf("choosing %s as main git branch in %s", branch, dir) | ||||
|  | ||||
| 	worktree, err := repo.Worktree() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	refName := fmt.Sprintf("refs/heads/%s", branch) | ||||
| 	checkOutOpts := &git.CheckoutOptions{ | ||||
| 		Create: false, | ||||
| 		Force:  true, | ||||
| 		Branch: plumbing.ReferenceName(refName), | ||||
| 		Branch: plumbing.ReferenceName(branch), | ||||
| 	} | ||||
| 	if err := worktree.Checkout(checkOutOpts); err != nil { | ||||
| 		logrus.Debugf("failed to check out '%s' in '%s'", refName, dir) | ||||
| 		logrus.Debugf("failed to check out %s in %s", branch, dir) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	logrus.Debugf("successfully checked out '%s' in '%s'", branch, dir) | ||||
| 	logrus.Debugf("successfully checked out %s in %s", branch, dir) | ||||
|  | ||||
| 	remote, err := repo.Remote("origin") | ||||
| 	if err != nil { | ||||
| @ -102,7 +97,7 @@ func EnsureUpToDate(dir string) error { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	logrus.Debugf("successfully fetched all changes in '%s'", dir) | ||||
| 	logrus.Debugf("successfully fetched all changes in %s", dir) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user