Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getStatus hangs #537

Closed
AdamStone opened this issue Apr 11, 2015 · 10 comments
Closed

getStatus hangs #537

AdamStone opened this issue Apr 11, 2015 · 10 comments

Comments

@AdamStone
Copy link

I'm trying the status example and finding that if uncommitted changes are present, although the example seems to work (prints filename MODIFIED), it doesn't return and I have to ctrl+C. I tried adding .done() at the end of each promise chain, but nothing gets thrown.

This also happens if I remove the details after getStatus(), but not if I remove getStatus() entirely, so this seems to originate in the getStatus() call itself. But if the directory is clean, it does return without printing anything.

Npm installed ^0.3.3.

Anyone know what's going on here?

@tbranyen
Copy link
Member

Looks to be a duplicate of: #497

@AdamStone
Copy link
Author

D'oh, I tried to search but I guess I was too focused on status/getStatus.

For now I'll just use the workaround from #497 of putting process.exit() in the .done() method.

@tommoor
Copy link

tommoor commented Dec 7, 2016

I'm still seeing this behavior in the latest 0.16 release - getStatus does not resolve sporadically - trying to dig into what might be causing this for us :(

@heath-guidewire
Copy link

heath-guidewire commented Apr 6, 2017

I'm still seeing this on 0.18.0. The first call to this method in my tests returns, the next one does not return and the .then() is not executed... same for any subsequent calls. It's almost like the first call leaves something in the thread that prevents any others from properly returning the promise

@tommoor
Copy link

tommoor commented Apr 6, 2017

@heath-guidewire we ended up completely removing use of getStatus from our code, instead diffing the index to working tree using NodeGit.Diff. Maybe that's a strategy you could take…

@heath-guidewire
Copy link

heath-guidewire commented Apr 6, 2017

Is there an example for this? Basically I want to know whether there have been any changes in the repo from the checked out version so that I can determine that I have to create a commit or not.

@tommoor
Copy link

tommoor commented Apr 6, 2017

Not sure about examples, but there is a method for it which works well and provides similar results to getStatus with a bit of massaging http://www.nodegit.org/api/diff/#indexToWorkdir

Something along the lines of:

Git.Diff.indexToWorkdir(repo, null, yourDiffOptions)
.then(diff => {
  const changes = {};
  for (let i = 0; i < diff.numDeltas(); i++) {
    const delta = diff.getDelta(i);
    const oldPath = delta.oldFile().path();
    const newPath = delta.newFile().path();
    const statusPath = oldPath || newPath;
    changes[statusPath] = delta.status();
  }
  return changes;
})
  

@heath-guidewire
Copy link

Hmm, even that command seems to have the same issue... Sometimes it works and sometimes it doesn't.

@tommoor
Copy link

tommoor commented Apr 6, 2017

We've not seen any issues with that one (across tens of thousands of commits), I'd definitely check the rest of your code thoroughly, sounds like this might not be where your issue lies - most likely an unreturned promise.

@heath-guidewire
Copy link

heath-guidewire commented Apr 6, 2017

I'm seeing a weird issue where repository.refreshIndex() does not return: Here's the code I have

  let repository;
  return nodegit.Repository.open(gitRepoPath())
    .then(repo => {
      repository = repo;
      console.log('repo opened');
      return repository.refreshIndex()
        .then(index => {
          console.log('read index', index);
          const flags = nodegit.Diff.OPTION.SHOW_UNTRACKED_CONTENT | nodegit.Diff.OPTION.RECURSE_UNTRACKED_DIRS;
          const diffOptions = {flags};
          return nodegit.Diff.indexToWorkdir(repository, index, diffOptions)
            .then(diff => {
              console.log('changes found', diff);
              const changes = {};
              for (let i = 0; i < diff.numDeltas(); i++) {
                const delta = diff.getDelta(i);
                const oldPath = delta.oldFile().path();
                const newPath = delta.newFile().path();
                const statusPath = oldPath || newPath;
                changes[statusPath] = delta.status();
              }
              return changes;
            })
        })
    });

I see the 'repo opened' message, but not the 'read index' message. Funny thing is that another method I have that uses refreshIndex() works. I swear I am totally missing something that's causing it to fail. Even using repository.index() seems to not return either.

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

No branches or pull requests

4 participants