MCPcopy
hub / github.com/git-lfs/git-lfs / migrateImportCommand

Function migrateImportCommand

commands/command_migrate_import.go:26–265  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

24)
25
26func migrateImportCommand(cmd *cobra.Command, args []string) {
27 ensureWorkingCopyClean(os.Stdin, os.Stderr)
28
29 l := tasklog.NewLogger(os.Stderr,
30 tasklog.ForceProgress(cfg.ForceProgress()),
31 )
32 defer l.Close()
33
34 db, err := getObjectDatabase()
35 if err != nil {
36 ExitWithError(err)
37 }
38 defer db.Close()
39
40 // To avoid confusion later, let's make sure that we've installed the
41 // necessary hooks so that a newly migrated repository is `git
42 // push`-able immediately following a `git lfs migrate import`.
43 installHooks(false)
44
45 if migrateNoRewrite {
46 if migrateFixup {
47 ExitWithError(errors.New(tr.Tr.Get("--no-rewrite and --fixup cannot be combined")))
48 }
49
50 if len(args) == 0 {
51 ExitWithError(errors.New(tr.Tr.Get("Expected one or more files with --no-rewrite")))
52 }
53
54 ref, err := git.CurrentRef()
55 if err != nil {
56 ExitWithError(errors.Wrap(err, tr.Tr.Get("Unable to find current reference")))
57 }
58
59 sha, _ := hex.DecodeString(ref.Sha)
60 commit, err := db.Commit(sha)
61 if err != nil {
62 ExitWithError(errors.Wrap(err, tr.Tr.Get("Unable to load commit")))
63 }
64
65 root := commit.TreeID
66
67 filter := git.GetAttributeFilter(cfg.LocalWorkingDir(), cfg.LocalGitDir())
68 if len(filter.Include()) == 0 {
69 ExitWithError(errors.New(tr.Tr.Get("No Git LFS filters found in '.gitattributes'")))
70 }
71
72 gf := lfs.NewGitFilter(cfg)
73
74 for _, file := range args {
75 if !filter.Allows(file) {
76 ExitWithError(errors.New(tr.Tr.Get("File %s did not match any Git LFS filters in '.gitattributes'", file)))
77 }
78 }
79
80 for _, file := range args {
81 root, err = rewriteTree(gf, db, root, file)
82 if err != nil {
83 ExitWithError(errors.Wrap(err, tr.Tr.Get("Could not rewrite %q", file)))

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
AppliedMethod · 0.95
AddMethod · 0.95
NewLoggerFunction · 0.92
ForceProgressFunction · 0.92
NewFunction · 0.92
CurrentRefFunction · 0.92
WrapFunction · 0.92
GetAttributeFilterFunction · 0.92
NewGitFilterFunction · 0.92
UpdateRefFunction · 0.92
NewOrderedSetFunction · 0.92

Tested by

no test coverage detected