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

StackOverflow https://stackoverflow.com/questions/16038188

  •  04-04-2022
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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!

Outras dicas

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.

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

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?
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top