1package cli
2
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7
8 "arche/internal/gitcompat"
9
10 "github.com/spf13/cobra"
11)
12
13var gitImportCmd = &cobra.Command{
14 Use: "git-import [git-repo-path]",
15 Short: "Import git history into the current arche repository (one-shot, no compat)",
16 Long: `Import the full commit history of a git repository into the current arche
17repository as public-phase commits.
18
19 arche git-import - import from the git repo in the current directory
20 arche git-import /path/to - import from the git repo at the given path
21
22This is a one-shot migration. Git compatibility is NOT enabled: arche will not
23mirror future snaps back to git and arche sync will not drive git push/pull.
24To keep git as a parallel history mirror, use "arche init --git" instead.
25
26The arche repository must already exist (run "arche init" first if needed).
27Bookmarks and HEAD are updated to match the imported tip.`,
28 Args: cobra.MaximumNArgs(1),
29 RunE: func(cmd *cobra.Command, args []string) error {
30 gitPath := "."
31 if len(args) == 1 {
32 gitPath = args[0]
33 }
34
35 absGitPath, err := filepath.Abs(gitPath)
36 if err != nil {
37 return fmt.Errorf("resolve path: %w", err)
38 }
39
40 if !gitcompat.IsGitRepo(absGitPath) {
41 return fmt.Errorf("%s is not a git repository (no .git/ found)", absGitPath)
42 }
43
44 r := openRepo()
45 defer r.Close()
46
47 fmt.Fprintf(os.Stdout, "Importing git history from %s ...\n", absGitPath)
48 if err := gitcompat.ImportFromGitOnce(absGitPath, r); err != nil {
49 return fmt.Errorf("git-import: %w", err)
50 }
51 fmt.Println("Import complete.")
52 head, _ := r.Head()
53 fmt.Printf("HEAD is now at %s\n", head)
54 return nil
55 },
56}