summaryrefslogtreecommitdiff
path: root/defaultBehavior.go
blob: c215aa23fe55e350f5afbb41743d3030fbc72689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"go.wit.com/log"
)

func defaultBehavior() error {
	// always run dirty first
	me.forge.CheckDirtyQuiet()

	// if no option is given to patch, list out the
	// repos that have patches ready in them
	found := findReposWithPatches()
	if found.Len() == 0 {
		log.Info("you currently have no repos with patches")
		return log.Errorf("no repos to publish")
	}
	// check if any are dirty
	for repo := range found.IterAll() {
		if repo.CheckDirty() {
			return log.Errorf("%s repo is dirty", repo.FullPath)
		}
	}
	// check the hashes
	for repo := range found.IterAll() {
		if err := hashesMatch(repo); err != nil {
			return err
		}
	}
	// move them all the the master branch
	var bad bool
	for repo := range found.IterAll() {
		if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
			repo.CheckoutMaster()
			bad = true
		}
	}
	if bad {
		return log.Errorf("some repos had to be switched to the master branch")
	}
	if !argv.Force {
		return log.Errorf("notsure. it might be safe to publish(?)")
	}
	return nil
}

func defaultBehaviorMaster() error {
	// always run dirty first
	me.forge.CheckDirtyQuiet()

	// if no option is given to patch, list out the
	// repos that have patches ready in them
	found := findReposWithPatches()
	if found.Len() == 0 {
		log.Info("you currently have no repos with patches")
		return nil
	}
	// warn about dirty repos not in master branches
	for repo := range found.IterAll() {
		if repo.CheckDirty() {
			if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
				repo.State = "DIRTY REPO NOT IN USER BRANCH"
			}
			// return log.Errorf("%s repo is dirty", repo.FullPath)
		}
	}
	me.forge.PrintDefaultTB(found)
	return nil
}