zlog
zlog

Reputation: 3316

How do I use rugged to check if there are uncommited changes in my git repository?

How do I use rugged to check whether there are uncommitted changes in my git repo?

Much like How do I programmatically determine if there are uncommited changes?

Upvotes: 5

Views: 511

Answers (4)

ioquatix
ioquatix

Reputation: 1476

You can get something similar to git status using Repository#status.

If you'd just like to check if there are any unstaged changes:

repository.to_enum(:status).any?

Upvotes: 0

James Milani
James Milani

Reputation: 1943

Wow. This question has been dead from some time, but thought I'd throw in my 2 cents as I'm using learning/using Rugged currently.

There's a handy method Repository#diff_workdir that exists nowadays.

Suppose you want to compare the working directory to the last commit( the equivalent of what I think of just a plain old git diff). You can get that with this:

repo.diff_workdir(repo.last_commit)

Hope this helps someone!

Upvotes: 2

Sergey Beduev
Sergey Beduev

Reputation: 352

Diff support was recently added. You can pull the latest version from github.

a = Rugged::Tree.lookup(repo, "806999").tree
b = Rugged::Tree.lookup(repo, "a8595c").tree

diff = a.diff(b)

deltas = diff.deltas
patches = diff.patches

Upvotes: 0

Carlos Martín Nieto
Carlos Martín Nieto

Reputation: 5277

You do it the same way. Either ask status or diff whether there are changes between HEAD and the worktree.

Rugged doesn't have diff support merged in yet, so you'd have to use status.

Upvotes: 0

Related Questions