librelist archives

« back to archive

Add/Commit with Rugged

Add/Commit with Rugged

From:
Stephanie Collett
Date:
2011-03-09 @ 22:24
Hi All, 

I¹m building an application using Grit right now, but I¹d like at to replace
(at least parts) with Rugged. I use Git for my version control, and have
found Grit simple to use because it has the same commands. I¹m having some
difficulty figuring out how to translate those commands into Rugged.

Specifically, I¹m trying to convert these Grit commands:

Repo = Grit::Repo.new(Œ.git¹)
repo.add(Œnew.txt¹)
repo.commit_all(Œcomment¹)

I¹ve loaded up the repository in Rugged, and have tried to add things to the
index:

repo = Rugged::Repository.new(Œgit¹)
index = repo.index
index.add(Œnew.txt¹)
Index.write

This is where I have issues. When I add Œnew.txt¹ and write, it stages
Œnew.txt¹ but it also stages deletes of other files already committed to the
repository, and puts those already committed files into the untracked files
at the same time. I¹m afraid with my limited understanding of Git internals
and Rugged I¹m butchering my repository.

How do I add a single file and commit it to a repository in Rugged?

Thanks,
Stephanie

Re: [libgit2] Add/Commit with Rugged

From:
Vicent Marti
Date:
2011-03-10 @ 22:38
Hey Stephanie,

there's two separate issues here. Here's a quick overview on how to
create commits with libgit2:


http://librelist.com/browser//libgit2/2011/2/19/initing-a-repository-adding-files-to-the-index-and-committing/#d94ce8df18ff0202ce904180286a4a85

As stated on my previous email, the process is exactly the same that
git.git uses -- and unfortunately, we still haven't implemented the
functionality to write the index as a tree to generate the commit. You
can, however, just manually change the tree to point to the new
version of your file (in your case, this would be much faster and
probably easier -- since you are just adding a file).

The other issue is the behavior regarding the index writing which you
are reporting. Seems strange (and unintended) to me. Could you
possibly give more information on what Rugged commands are you using,
and what does your repository look like?

Cheers,
Vicent Marti



On Thu, Mar 10, 2011 at 12:24 AM, Stephanie Collett
<stephanie.collett@ucop.edu> wrote:
>
> Hi All,
>
> I’m building an application using Grit right now, but I’d like at to replace
> (at least parts) with Rugged. I use Git for my version control, and have
> found Grit simple to use because it has the same commands. I’m having some
> difficulty figuring out how to translate those commands into Rugged.
>
> Specifically, I’m trying to convert these Grit commands:
>
> Repo = Grit::Repo.new(‘.git’)
> repo.add(‘new.txt’)
> repo.commit_all(‘comment’)
>
> I’ve loaded up the repository in Rugged, and have tried to add things to the
> index:
>
> repo = Rugged::Repository.new(‘git’)
> index = repo.index
> index.add(‘new.txt’)
> Index.write
>
> This is where I have issues. When I add ‘new.txt’ and write, it stages
> ‘new.txt’ but it also stages deletes of other files already committed to the
> repository, and puts those already committed files into the untracked files
> at the same time. I’m afraid with my limited understanding of Git internals
> and Rugged I’m butchering my repository.
>
> How do I add a single file and commit it to a repository in Rugged?
>
> Thanks,
> Stephanie
>

Re: [libgit2] Add/Commit with Rugged

From:
Stephanie Collett
Date:
2011-03-11 @ 19:18
Hi Vicent,

Thanks, the previous email you linked to is helpful. I'll try to follow the
suggestions for getting around the unimplemented method.

Here is what I did in Rugged which produced unexpected results in the index
file. I was using rugged (0.1.2), libgit2 (0.8.0), and ruby-1.9.2-preview3
in RVM on OS X 10.6.

1) I created three files with some plain text: first.txt, second.txt,
third.txt in a directory.

2) Using git in the command line, I created a git repository and committed
the first.txt and second.txt file. I left the third.txt file untracked.

$ git add first.txt
$ git commit -m "first"
[master (root-commit) 56cc0b2] first
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 first.txt
$ git add second.txt
$ git commit -m "second"
[master 8daaed8] second
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 second.txt
$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# third.txt 

3) I fired up the IRB and tried to stage the third.txt file.

$ irb
ruby > require 'rugged'
=> true
ruby > repo = Rugged::Repository.new('.git')
=> #<Rugged::Repository:0x763d9c>
ruby > index = repo.index
=> #<Rugged::Index:0x734754>
ruby > index.add('third.txt')
=> nil
ruby > index.count
=> 1
ruby > index.write
=> nil  

4) I then went back to the command line and ran a 'git status'

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# deleted:    first.txt
# deleted:    second.txt
# new file:   third.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# first.txt
# second.txt 

I'm not sure if this is a bug, or if I was missing parameters and/or using
the incorrect methods.

Thanks,
Stephanie

On 3/10/11 2:38 PM, "Vicent Marti" <tanoku@gmail.com> wrote:

> Hey Stephanie,
> 
> there's two separate issues here. Here's a quick overview on how to
> create commits with libgit2:
> 
> http://librelist.com/browser//libgit2/2011/2/19/initing-a-repository-adding-fi
> les-to-the-index-and-committing/#d94ce8df18ff0202ce904180286a4a85
> 
> As stated on my previous email, the process is exactly the same that
> git.git uses -- and unfortunately, we still haven't implemented the
> functionality to write the index as a tree to generate the commit. You
> can, however, just manually change the tree to point to the new
> version of your file (in your case, this would be much faster and
> probably easier -- since you are just adding a file).
> 
> The other issue is the behavior regarding the index writing which you
> are reporting. Seems strange (and unintended) to me. Could you
> possibly give more information on what Rugged commands are you using,
> and what does your repository look like?
> 
> Cheers,
> Vicent Marti
> 
> 
> 
> On Thu, Mar 10, 2011 at 12:24 AM, Stephanie Collett
> <stephanie.collett@ucop.edu> wrote:
>> 
>> Hi All,
>> 
>> I¹m building an application using Grit right now, but I¹d like at to replace
>> (at least parts) with Rugged. I use Git for my version control, and have
>> found Grit simple to use because it has the same commands. I¹m having some
>> difficulty figuring out how to translate those commands into Rugged.
>> 
>> Specifically, I¹m trying to convert these Grit commands:
>> 
>> Repo = Grit::Repo.new(Œ.git¹)
>> repo.add(Œnew.txt¹)
>> repo.commit_all(Œcomment¹)
>> 
>> I¹ve loaded up the repository in Rugged, and have tried to add things to the
>> index:
>> 
>> repo = Rugged::Repository.new(Œgit¹)
>> index = repo.index
>> index.add(Œnew.txt¹)
>> Index.write
>> 
>> This is where I have issues. When I add Œnew.txt¹ and write, it stages
>> Œnew.txt¹ but it also stages deletes of other files already committed to the
>> repository, and puts those already committed files into the untracked files
>> at the same time. I¹m afraid with my limited understanding of Git internals
>> and Rugged I¹m butchering my repository.
>> 
>> How do I add a single file and commit it to a repository in Rugged?
>> 
>> Thanks,
>> Stephanie
>>