代码拉取完成,页面将自动刷新
同步操作将从 开源中国/git-repo-clean 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"fmt"
"os"
)
func InitContext(args []string) *Repository {
var op = Options{}
if err := op.ParseOptions(args); err != nil {
PrintLocalWithRedln("Parse Option error")
os.Exit(1)
}
if len(args) == 0 {
op.interact = true
}
r, err := NewRepository(op.path)
if err != nil {
PrintLocalWithRedln(LocalPrinter().Sprintf("%s", err))
os.Exit(1)
}
// check if current repo has uncommited files
if err = GetCurrentStatus(r.gitBin, r.path); err != nil {
PrintLocalWithRedln(LocalPrinter().Sprintf("%s", err))
os.Exit(1)
}
// set default branch to all is to keep deleting process consistent with scanning process
// user end pass '--branch=all', but git-fast-export takes '--all'
if op.branch == "all" {
op.branch = "--all"
}
return &Repository{
op.path,
r.gitBin,
r.gitDir,
r.bare,
op,
}
}
func NewFilter(args []string) (*RepoFilter, error) {
var repo = InitContext(args)
err := repo.GetBlobSize()
if err != nil {
ft := LocalPrinter().Sprintf("run getblobsize error: %s", err)
PrintRedln(ft)
}
var first_target []string
var scanned_targets []string
var file_paths []string
// when run git-repo-clean -i, its means run scan too
if repo.opts.interact {
repo.opts.scan = true
repo.opts.delete = true
repo.opts.verbose = true
repo.opts.lfs = true
if err := repo.opts.SurveyCmd(); err != nil {
ft := LocalPrinter().Sprintf("ask question module fail: %s", err)
PrintRedln(ft)
os.Exit(1)
}
}
if repo.opts.lfs {
repo.opts.scan = true
}
PrintLocalWithPlain("current repository size")
PrintLocalWithYellowln(repo.GetDatabaseSize())
if lfs := repo.GetLFSObjSize(); len(lfs) > 0 {
PrintLocalWithPlain("including LFS objects size")
PrintLocalWithYellowln(lfs)
}
if repo.opts.scan {
bloblist, err := repo.ScanRepository()
if err != nil {
ft := LocalPrinter().Sprintf("scanning repository error: %s", err)
PrintRedln(ft)
os.Exit(1)
}
if len(bloblist) == 0 {
PrintLocalWithRedln("no files were scanned")
os.Exit(1)
} else {
repo.ShowScanResult(bloblist)
}
if repo.opts.interact {
first_target = MultiSelectCmd(bloblist)
if len(bloblist) != 0 && len(first_target) == 0 {
PrintLocalWithRedln("no files were selected")
os.Exit(1)
}
var ok = false
ok, scanned_targets = Confirm(first_target)
if !ok {
PrintLocalWithRedln("operation aborted")
os.Exit(1)
}
} else {
for _, item := range bloblist {
scanned_targets = append(scanned_targets, item.oid)
}
}
// record target file's name
for _, item := range bloblist {
for _, target := range scanned_targets {
if item.oid == target {
Files_changed.Add(item.objectName)
}
}
}
} else {
if repo.opts.file != nil {
file_paths = repo.opts.file
repo.opts.limit = ""
}
if repo.opts.limit != "" {
repo.opts.number = ^uint32(0) // UINT_MAX
}
}
if !repo.opts.delete {
os.Exit(1)
}
return &RepoFilter{
repo: repo,
scanned: scanned_targets,
filepaths: file_paths}, nil
}
func LFSPrompt(repo Repository) {
FilesChanged()
PrintLocalWithPlainln("before you push to remote, you have to do something below:")
PrintLocalWithYellowln("1. install git-lfs")
PrintLocalWithYellowln("2. run command: git lfs install")
PrintLocalWithYellowln("3. edit .gitattributes file")
PrintLocalWithYellowln("4. commit your .gitattributes file.")
}
func Prompt(repo Repository) {
PrintLocalWithGreenln("cleaning completed")
PrintLocalWithPlain("current repository size")
PrintLocalWithYellowln(repo.GetDatabaseSize())
if lfs := repo.GetLFSObjSize(); len(lfs) > 0 {
PrintLocalWithPlain("including LFS objects size")
PrintLocalWithYellowln(lfs)
}
if repo.opts.lfs {
LFSPrompt(repo)
}
var pushed bool
if !repo.opts.lfs {
if AskForUpdate() {
PrintLocalWithPlainln("execute force push")
PrintLocalWithYellowln("git push origin --all --force")
PrintLocalWithYellowln("git push origin --tags --force")
err := repo.PushRepo()
if err == nil {
pushed = true
}
}
}
PrintLocalWithPlainln("suggest operations header")
if pushed {
PrintLocalWithGreenln("1. (Done!)")
fmt.Println()
} else {
PrintLocalWithRedln("1. (Undo)")
PrintLocalWithRedln(" git push origin --all --force")
PrintLocalWithRedln(" git push origin --tags --force")
fmt.Println()
}
PrintLocalWithRedln("2. (Undo)")
url := repo.GetGiteeGCWeb()
if url != "" {
PrintLocalWithRed("gitee GC page link")
PrintYellowln(url)
}
fmt.Println()
PrintLocalWithRedln("3. (Undo)")
PrintLocalWithRed("for detailed documentation, see")
PrintYellowln("https://gitee.com/oschina/git-repo-clean/blob/main/docs/repo-update.md")
fmt.Println()
PrintLocalWithPlainln("suggest operations done")
PrintLocalWithPlainln("introduce GIT LFS")
PrintLocalWithPlain("for the use of Gitee LFS, see")
PrintYellowln("https://gitee.com/help/articles/4235")
}
func main() {
filter, err := NewFilter(os.Args[1:])
if err != nil {
LocalFprintf(os.Stderr, "init repo filter error")
os.Exit(1)
}
// repo backup
filter.repo.BackUp()
// ask for lfs migrate
if filter.repo.opts.lfs && AskForMigrateToLFS() {
// can't run lfs-migrate in bare repo
if filter.repo.bare {
PrintLocalWithYellowln("bare repo error")
os.Exit(1)
}
} else {
filter.repo.opts.lfs = false
}
// filter data
filter.Parser()
filter.repo.CleanUp()
Prompt(*filter.repo)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。