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.
 | 
					// Clone runs a git clone which accounts for different default branches.
 | 
				
			||||||
func Clone(dir, url string) error {
 | 
					func Clone(dir, url string) error {
 | 
				
			||||||
	if _, err := os.Stat(dir); os.IsNotExist(err) {
 | 
						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})
 | 
							_, err := git.PlainClone(dir, false, &git.CloneOptions{URL: url, Tags: git.AllTags})
 | 
				
			||||||
		if err != nil {
 | 
							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{
 | 
								_, err := git.PlainClone(dir, false, &git.CloneOptions{
 | 
				
			||||||
				URL:           url,
 | 
									URL:           url,
 | 
				
			||||||
				Tags:          git.AllTags,
 | 
									Tags:          git.AllTags,
 | 
				
			||||||
@ -32,9 +32,9 @@ func Clone(dir, url string) error {
 | 
				
			|||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		logrus.Debugf("'%s' has been git cloned successfully", dir)
 | 
							logrus.Debugf("%s has been git cloned successfully", dir)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logrus.Debugf("'%s' already exists, doing nothing", dir)
 | 
							logrus.Debugf("%s already exists, doing nothing", dir)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
@ -54,37 +54,32 @@ func EnsureUpToDate(dir string) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !isClean {
 | 
						if !isClean {
 | 
				
			||||||
		return fmt.Errorf("'%s' has locally unstaged changes", recipeName)
 | 
							return fmt.Errorf("%s has locally unstaged changes", recipeName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	branch := "master"
 | 
						branch, err := GetCurrentBranch(repo)
 | 
				
			||||||
	if _, err := repo.Branch("master"); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		if _, err := repo.Branch("main"); err != nil {
 | 
							return err
 | 
				
			||||||
			logrus.Debugf("failed to select branch in '%s'", dir)
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		branch = "main"
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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()
 | 
						worktree, err := repo.Worktree()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	refName := fmt.Sprintf("refs/heads/%s", branch)
 | 
					 | 
				
			||||||
	checkOutOpts := &git.CheckoutOptions{
 | 
						checkOutOpts := &git.CheckoutOptions{
 | 
				
			||||||
		Create: false,
 | 
							Create: false,
 | 
				
			||||||
		Force:  true,
 | 
							Force:  true,
 | 
				
			||||||
		Branch: plumbing.ReferenceName(refName),
 | 
							Branch: plumbing.ReferenceName(branch),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := worktree.Checkout(checkOutOpts); err != nil {
 | 
						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
 | 
							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")
 | 
						remote, err := repo.Remote("origin")
 | 
				
			||||||
	if err != nil {
 | 
						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
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user