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

package main

import (
	"path/filepath"

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

// is every repo on the devel branch?
func doFix() (string, error) {
	if argv.Fixer.Urls {
		err := doFixUrls()
		return "", err
	}
	if argv.Fixer.Untracked {
		return doRemoveUntrackedFiles()
	}
	if argv.Fixer.DeleteUser {
		return doDeleteUser()
	}
	return "", nil
}

func doRemoveUntrackedFiles() (string, error) {
	// show untracked files
	// git ls-files --others
	// git ls-files --others --exclude-standard
	// git ls-files --others --ignored --exclude-standard
	var count int
	var filelist []string
	found := gitpb.NewRepos()
	for repo := range me.forge.Repos.IterByNamespace() {
		var err error
		r, err := repo.RunQuiet([]string{"git", "ls-files", "--others"})
		if err != nil {
			continue
		}
		if len(r.Stdout) == 0 {
			continue
		}
		count += len(r.Stdout)
		for _, fname := range r.Stdout {
			filelist = append(filelist, filepath.Join(repo.FullPath, fname))
		}
		repo.State = log.Sprintf("%d files", len(r.Stdout))
		found.Append(repo)
	}
	me.forge.PrintHumanTable(found)
	log.Info("")
	log.Info("You have %d files that are untracked excluded git files. They are probably junk.", count)
	log.Info("")
	log.Info("You can remove these files with '--fix' or list them all with '--verbose'")
	log.Info("")
	if argv.Force {
		log.Info("todo: unlink them")
	}
	if argv.Verbose {
		for _, fname := range filelist {
			log.Info(fname)
		}
	}
	return "use --force to actually remove them", nil
}