Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

add support for directories on git add (was: git add . doesn't seem to work) #456

Closed
jucardi opened this issue Jun 30, 2017 · 11 comments
Closed

Comments

@jucardi
Copy link

jucardi commented Jun 30, 2017

I'm trying to add all contents in a cloned repo. Normally I would do this with the command line by doing a

git add .

I'm trying to do it by running

if _,err = workTree.Add("."); err != nil {

But that actually returns an error saying

read [path]: is a directory

Do I need to add file by file by hand?

@mcuadros
Copy link
Contributor

Worktree.Add only works with files, directories are not handled, but PRs are welcome.

@smola smola changed the title git add . doesn't seem to work add support for directories on git add (was: git add . doesn't seem to work) Jun 30, 2017
@halfcrazy
Copy link

@jucardi What's the current status of your PR?

@joshbetz
Copy link
Contributor

joshbetz commented Dec 20, 2017

I've been doing this, but it's pretty slow.

	status, err := worktree.Status()
	if err != nil {
		return err
	}

	if status.IsClean() {
		return nil
	}

	for path, _ := range status {
		worktree.Add(path)
	}

@Labutin
Copy link
Contributor

Labutin commented Dec 28, 2017

Yes, it really TOO slow.
I need to commit about 500 updated files and calling worktree.Add(path) for all files takes more than 3 minutes :(
Using CommitOptions.All doing the same loop over all modified files and works the same slow.
Any ideas how to commit 500 updated files faster?

@mcuadros
Copy link
Contributor

The complexity of the Add is almost trivial, the time consumed is on doing the hashing. How big are the files? How many time takes on git command, @Labutin?

@Labutin
Copy link
Contributor

Labutin commented Dec 28, 2017

I have about 500 modified files. Each file about 22KB size. Not so big.

dlabutin@dlabutin-mbp $ git status| wc
     529    1085   26114
dlabutin@dlabutin-mbp $ time git add .
real	0m0.092s
user	0m0.041s
sys	0m0.046s

Console git add . takes less than 0.1 sec.
But

	if _, err := w.Commit("Commit message", &git.CommitOptions{
		All: true,
		Author: &object.Signature{
			Name: "octopus",
			Email: "octopus@server",
			When: time.Now(),
		},
	}); err != nil {
		return err
	}

works about 3 minutes.
I am testing on Macbook Pro (SSD drive).

@Labutin
Copy link
Contributor

Labutin commented Dec 28, 2017

Looks like problem is here: https://github.com/src-d/go-git/blob/master/worktree_status.go#L248

Calling s, err := w.Status() for every added file takes many time :(

@Labutin
Copy link
Contributor

Labutin commented Dec 28, 2017

I tried to use dirty hack and cache Worktree status inside Add. Now adding 500 files take about 20 seconds. Not so fast as console command. But much better than 3 minutes.

@mcuadros
Copy link
Contributor

mcuadros commented Dec 28, 2017

git client is always multi-threaded go-git, itsn't it.

@Labutin
Copy link
Contributor

Labutin commented Dec 28, 2017

Even if git client is multi-threaded I don't think it rereads working tree status for every added file.

@joshbetz
Copy link
Contributor

@Labutin Maybe you can send a PR with your changes? A 9x performance improvement sounds pretty good to me :)

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

No branches or pull requests

5 participants