extism / cli

The extism CLI is used to generate plugin scaffolding and manage Extism installations
BSD 3-Clause "New" or "Revised" License
19 stars 5 forks source link

feat: gen plugin automatically initializes submodules after cloning the template repo #88

Closed mhmd-azeez closed 1 month ago

mhmd-azeez commented 1 month ago

Fixes #87

PS D:\dylibso\cli\extism> go run . generate plugin -o d:/x/xtp/c-1 -l C
Cloning into 'd:/x/xtp/c-1'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 0), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Submodule 'extism' (https://github.com/extism/c-pdk) registered for path 'extism'
Cloning into 'D:/x/xtp/c-1/extism'...
Submodule path 'extism': checked out '68a42171becc1712cc9c91d3feee147e5fecdb2a'
Switched to a new branch 'extism-init'
[extism-init (root-commit) 850d0a3] init: extism
 7 files changed, 69 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .gitmodules
 create mode 100644 LICENSE
 create mode 100644 Makefile
 create mode 100644 README.md
 create mode 160000 extism
 create mode 100644 src/plugin.c
Generated C plugin scaffold at d:/x/xtp/c-1
nilslice commented 1 month ago

It seems ok -- since that new "delete the .git repo if a parent one exists" code runs after this process:

// ...
// initialize submodules if any
    if _, err := os.Stat(filepath.Join(dir, ".gitmodules")); err == nil {
        if err := runCmdInDir(dir, "git", "submodule", "update", "--init", "--recursive"); err != nil {
            return err
        }
    }
    absDir, err := filepath.Abs(dir)
    if err != nil {
        return err
    }
    if hasGitRepoInParents(absDir, 100) { // <--- this should take care of any cleanup we'd want
        if err := os.RemoveAll(filepath.Join(dir, ".git")); err != nil {
            return err
        }
    } else {
/// ...
nilslice commented 1 month ago

I am not sure if there is any downside to removing the .git dir when submodules are involved.. I'd assume they become "vendored" into the project vs. a link.

mhmd-azeez commented 1 month ago

I am not sure if there is any downside to removing the .git dir when submodules are involved.. I'd assume they become "vendored" into the project vs. a link.

In that case maybe people can manually add the submodule to the parent repo, since the .gitmodules file is still present

mhmd-azeez commented 1 month ago

ah, good idea to use the original clone!

@bhelx is a git wizard 🪄

bhelx commented 1 month ago

I assume it’s safe whether the module has sub modules or not but please double check On May 23, 2024 at 6:06 PM -0500, Muhammad Azeez @.***>, wrote:

Merged #88 into main. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

mhmd-azeez commented 1 month ago

I assume it’s safe whether the module has sub modules or not but please double check

tested it with the go pdk template, seems to be working