checkpoint: can clone repo to temp dir
This commit is contained in:
parent
e98c422970
commit
823252fe4d
2 changed files with 43 additions and 24 deletions
|
@ -193,5 +193,11 @@
|
||||||
"user-dirs.dirs",
|
"user-dirs.dirs",
|
||||||
"user-dirs.locale",
|
"user-dirs.locale",
|
||||||
"zk"
|
"zk"
|
||||||
]
|
],
|
||||||
|
"neovim": {
|
||||||
|
"manage": true,
|
||||||
|
"gitRepoURL": "https://codeflow.dananglin.me.uk/linux-home/nvim.d.git",
|
||||||
|
"gitRef": "746f07efdb203a46a7a02ada987cd97b68fa92d6",
|
||||||
|
"gitRepoPath": "nvim"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"slices"
|
||||||
|
|
||||||
|
"github.com/magefile/mage/sh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Neovim downloads and manages neovim configuration from a remote git repository.
|
// Neovim downloads and manages neovim configuration from a remote git repository.
|
||||||
|
@ -22,30 +24,28 @@ func Neovim() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
homeConfigDirectory, err := os.UserConfigDir()
|
//homeConfigDirectory, err := os.UserConfigDir()
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return fmt.Errorf(
|
// return fmt.Errorf(
|
||||||
"unable to get the user's home configuration directory: %w",
|
// "unable to get the user's home configuration directory: %w",
|
||||||
err,
|
// err,
|
||||||
)
|
// )
|
||||||
}
|
//}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
neovimManagedDir = filepath.Join(rootManagedDir, "nvim")
|
// neovimManagedDir = filepath.Join(rootManagedDir, "nvim")
|
||||||
versionLabelFile = filepath.Join(neovimManagedDir, ".managed.version")
|
// versionLabelFile = filepath.Join(neovimManagedDir, ".managed.version")
|
||||||
neovimConfigDir = filepath.Join(homeConfigDirectory, "nvim")
|
// neovimConfigDir = filepath.Join(homeConfigDirectory, "nvim")
|
||||||
)
|
)
|
||||||
|
|
||||||
tempLocalRepo, err := cloneNvimConfigRepo(config.Neovim., config.Neovim.)
|
tempLocalRepo, err := cloneNvimConfigRepo(config.Neovim.GitRepoURL, config.Neovim.GitRef)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to clone the git repository: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
fmt.Println("Git repository cloned to:", tempLocalRepo)
|
||||||
if err := os.Remove(tempLocalRepo); err != nil {
|
|
||||||
return fmt.Errorf(
|
// defer os.Remove(tempLocalRepo)
|
||||||
"received an error while trying to remove %s: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// TODO: copy the files from temp folder to managed folder
|
// TODO: copy the files from temp folder to managed folder
|
||||||
|
|
||||||
|
@ -57,12 +57,25 @@ func Neovim() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneNvimConfigRepo(repoURL, repoRef string) (string, error) {
|
func cloneNvimConfigRepo(repoURL, repoRef string) (string, error) {
|
||||||
tempDir, err := os.MkdirTemp("/tmp", "neovim-config-")
|
cloneDir, err := os.MkdirTemp("/tmp", "neovim-config-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to create the temporary directory: %w", err)
|
return "", fmt.Errorf("unable to create the temporary directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clone the repo to the tempDir and return tempDir
|
git := sh.RunCmd("git", "-C", cloneDir)
|
||||||
|
|
||||||
return tempDir, nil
|
commands := [][]string{
|
||||||
|
{"init"},
|
||||||
|
{"remote", "add", "origin", repoURL},
|
||||||
|
{"fetch", "origin", repoRef},
|
||||||
|
{"checkout", "FETCH_HEAD"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, command := range slices.All(commands) {
|
||||||
|
if err := git(command...); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cloneDir, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue