// 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(f *FixCmd) (string, error) { var s string var err error if f.Urls { err = doFixUrls() } if f.Untracked { return doRemoveUntrackedFiles() } if f.DeleteUser { return doDeleteUser() } if f.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 f.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 }