summaryrefslogtreecommitdiff
path: root/doDirty.go
blob: a2a38ec8591f33ab89c074cb48d83a80c8f0d82d (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"time"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func doDirty() {
	doCheckDirtyAndConfigSave()

	found := findDirty()
	if found.Len() == 0 {
		return
	}
	if argv.Verbose {
		me.forge.PrintHumanTableDirty(found)
	} else {
		me.forge.PrintHumanTable(found)
	}
}

func straightCheckDirty() int {
	var count int
	// var total int
	// now := time.Now()
	for repo := range me.forge.Repos.IterAll() {
		// total += 1
		if repo.IsDirty() {
			count += 1
		}
	}
	// log.Printf("rill dirty check (%d dirty repos) (%d total repos) took:%s\n", count, total, shell.FormatDuration(time.Since(now)))
	return count
}

func doCheckDirty(repo *gitpb.Repo) error {
	repo.CheckDirty()
	// reset these in here for now
	if repo.GetTargetVersion() != "" {
		repo.TargetVersion = ""
		me.forge.SetConfigSave(true)
	}
	return nil
}

// recheck every repo's dirty state according to 'git'
func doCheckDirtyAndConfigSave() {
	start := straightCheckDirty()

	now := time.Now()
	me.forge.RillFuncError(doCheckDirty)
	end := straightCheckDirty()
	log.Printf("dirty check (%d dirty repos) (%d total repos) took:%s\n", end, me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))

	if start != end {
		// todo: use internal forgepb configsave flag. should work?
		me.forge.SetConfigSave(true)
		me.forge.ConfigSave()
	}
}