Is there a specific protocol to add everything to Git using Rugged?

153 views Asked by At

I recently began using Rugged, and have already run into some problems. Basically all I want to do is add everything in a Git repo, commit the staged changes, and push everything to a branch. I've started out with the first step as follows:

@repo = Rugged::Repository.new(Dir.pwd)
@index = @repo.index

def git_add
    @index.add mode: 'add-all'
end

But the console ends up screaming at me. I browsed through libgit2's documentation, and couldn't find any examples of adding everything in repo. Some thorough Googling yielded similar results. I could probably have just jammed in a @repo.workdir.entries as the path parameter for index.add, but I'm not sure. Is there a better way to go about this?

1

There are 1 answers

0
Carlos Martín Nieto On BEST ANSWER

Depending on whether you want to stage every file or just the ones which are already in, you have two options, Index#add_all and Index#update_all respectively.

You can use repo.index.add_all() to stage every file under the specified directory. You can use repo.index.update_all() to do the same but only for those files which are already known to the repository, similarly to git's -A and -u options.