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

Cloning to current directory? #1087

Open
thebigbone opened this issue Apr 29, 2024 · 9 comments
Open

Cloning to current directory? #1087

thebigbone opened this issue Apr 29, 2024 · 9 comments

Comments

@thebigbone
Copy link

Hello, I wanted to clone a repository to the current directory and therefore I used ".".

_, err := git.PlainClone(".", false, &git.CloneOptions{
	  URL:      r.URL,
	  Progress: os.Stdout,
})

But that doesn't seem to working. I get the following error:

git clone https://github.com/thebigbone/load-balancer{"time":"2024-04-29T21:55:09.53592634+05:30","level":"FATAL","prefix":"-","file":"cmd.go","line":"44","message":"repository already exists"}
exit status 1

What's the current way to clone to current directory?

@thebigbone
Copy link
Author

thebigbone commented Apr 29, 2024

It seems like using ./directory-name works which is slightly different.

Edit: Accidentally closed the issue.

@onee-only
Copy link
Contributor

Could you check if you have already initialized git repository in the current directory?

@thebigbone
Copy link
Author

Could you check if you have already initialized git repository in the current directory?

Is that necessary for cloning a repository?

@onee-only
Copy link
Contributor

If you clone a repository via PlainClone, go-git will use .git directory for git repository.
And if you already have initialized a git repository there, it will produce an error since repositories cannot coexist in the same directory.

@thebigbone
Copy link
Author

Oh, I see. Is there any way for cloning without initializing .git directory?

@onee-only
Copy link
Contributor

You can store repository in memory.
Please refer to the code snippet below.

package main

import (
	"github.com/go-git/go-billy/v5/memfs"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	fs := memfs.New()
	s := memory.NewStorage()
	r, err := git.Clone(s, fs, &git.CloneOptions{
		URL: "your git repository",
	})
}

You might want to avoid using memory storage if you are cloning large repository or etc.

@thebigbone
Copy link
Author

You can store repository in memory. Please refer to the code snippet below.

package main

import (
	"github.com/go-git/go-billy/v5/memfs"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	fs := memfs.New()
	s := memory.NewStorage()
	r, err := git.Clone(s, fs, &git.CloneOptions{
		URL: "your git repository",
	})
}

You might want to avoid using memory storage if you are cloning large repository or etc.

That looks helpful, thanks. But I would like to stick to the PlainClone because storing it in memory is not possible due to memory constraints. I can work on a PR for this if you want to consider it as an option.

@onee-only
Copy link
Contributor

That looks helpful, thanks. But I would like to stick to the PlainClone because storing it in memory is not possible due to memory constraints. I can work on a PR for this if you want to consider it as an option

I'm not sure if this project is planning on supporting this kind of use case.
Are there any other options @pjbgf ?

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

No branches or pull requests

3 participants
@thebigbone @onee-only and others