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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// 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"
)
func getPorcelain() (string, error) {
s, err := me.forge.Repos.CheckPorcelain()
return s, err
}
// is every repo on the devel branch?
func doFix() (string, error) {
var s string
var err error
if argv.Fixer.Urls {
err = doFixUrls()
}
if argv.Fixer.Untracked {
return doRemoveUntrackedFiles()
}
if argv.Fixer.DeleteUser {
return doDeleteUser()
}
if argv.Fixer.Prune {
// git fetch --prune
for repo := range me.forge.Repos.IterByNamespace() {
if me.forge.Config.IsReadOnly(repo.Namespace) {
continue
}
repo.RunVerbose([]string{"git", "fetch", "--prune"})
}
}
if argv.Fixer.Porcelain != nil {
s, err = getPorcelain()
log.Info("GET PORCELAIN SENT BACK", s, err)
for repo := range me.forge.Repos.IterByFullPath() {
curbranch := repo.GetCurrentBranchName()
repo.RunVerbose([]string{"bash", "-c", "git show-ref |grep -v tags"})
repo.ReloadForce()
repo.RunVerbose([]string{"bash", "-c", "git show-ref |grep -v tags"})
if repo.IsLocalBranch(curbranch) {
log.Info(repo.FullPath, "SEEMS TO HAVE A '", curbranch, "' LOCAL BRANCH")
continue
}
if repo.IsRemoteBranch(curbranch) {
log.Info(repo.FullPath, "SEEMS TO HAVE A '", curbranch, "' REMOTE BRANCH")
continue
}
log.Info("curbranch is doesn't exist. this'll cause all sorts of problems", curbranch, repo.FullPath)
log.Info("checking out with force", repo.FullPath)
repo.CheckoutForce()
repo.RunVerbose([]string{"git", "branch"})
// panic("did this work?") // yes, it does work. it still needs work. branch handling is wrong in gitpb
}
me.forge.Repos.Save()
}
return s, err
}
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)
}
footer := found.PrintDefaultTB()
log.Info(footer)
log.Printf("You have %d files that are untracked excluded git files. They are probably junk.\n", 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
}
|