Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 23, 2024

Conversation

mhmd-azeez
Copy link
Contributor

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

@mhmd-azeez mhmd-azeez requested review from zshipko and nilslice May 23, 2024 22:02
Copy link
Contributor

@zshipko zshipko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but wondering if @nilslice thinks this works with the changes to detect existing git repos?

@nilslice
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

mhmd-azeez commented May 23, 2024

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

Copy link
Member

@nilslice nilslice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good idea to use the original clone!

@mhmd-azeez mhmd-azeez merged commit 88d30c6 into main May 23, 2024
7 checks passed
@mhmd-azeez mhmd-azeez deleted the init-submodules branch May 23, 2024 23:06
@mhmd-azeez
Copy link
Contributor Author

ah, good idea to use the original clone!

@bhelx is a git wizard 🪄

@bhelx
Copy link
Contributor

bhelx commented May 23, 2024 via email

@mhmd-azeez
Copy link
Contributor Author

mhmd-azeez commented May 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialize git submodules after cloning a template repo
4 participants