powerline-gitstatus icon indicating copy to clipboard operation
powerline-gitstatus copied to clipboard

IndexError: pop from empty list error

Open gepinita opened this issue 9 years ago • 13 comments

Hello, I have noticed the following error sometimes.

> git status
# On branch master
nothing to commit (working directory clean)
2015-06-17 19:49:41,251:ERROR:shell:gitstatus:Exception while computing segment: pop from empty list
Traceback (most recent call last):
  File "/home/user/.local/lib/python2.7/site-packages/powerline/segment.py", line 173, in process_segment
    contents = segment['contents_func'](pl, segment_info)
  File "/home/user/.local/lib/python2.7/site-packages/powerline/segment.py", line 412, in <lambda>
    contents_func = lambda pl, segment_info: _contents_func(pl=pl, segment_info=segment_info, **args)
  File "/home/user/.local/lib/python2.7/site-packages/powerline_gitstatus/segments.py", line 127, in __call__
    branch, detached, behind, ahead = self.parse_branch(status.pop(0))
IndexError: pop from empty list

gepinita avatar Jun 17 '15 18:06 gepinita

Can you set the log-level to DEBUG and give about 10 lines above an error like this? That would show the git output the segment is trying to parse.

Thanks!

jaspernbrouwer avatar Jun 17 '15 18:06 jaspernbrouwer

It seems that the git porcelain command returns an empty segment when repo is clean.

2015-06-17 20:21:38,188:DEBUG:shell:watcher:Trying to use inotify watcher
2015-06-17 20:21:38,196:DEBUG:shell:gitstatus:Running gitstatus without -C
2015-06-17 20:21:38,196:DEBUG:shell:gitstatus:Executing command: git --git-dir=/home/user/Code/git/llvm/.git --work-tree=/home/user/Code/git/llvm status --branch --porcelain
2015-06-17 20:21:38,272:ERROR:shell:gitstatus:Exception while computing segment: pop from empty list
Traceback (most recent call last):
  File "/home/user/.local/lib/python2.7/site-packages/powerline/segment.py", line 173, in process_segment
    contents = segment['contents_func'](pl, segment_info)
  File "/home/user/.local/lib/python2.7/site-packages/powerline/segment.py", line 412, in <lambda>
    contents_func = lambda pl, segment_info: _contents_func(pl=pl, segment_info=segment_info, **args)
  File "/home/user/.local/lib/python2.7/site-packages/powerline_gitstatus/segments.py", line 127, in __call__
    branch, detached, behind, ahead = self.parse_branch(status.pop(0))
IndexError: pop from empty list

gepinita avatar Jun 17 '15 19:06 gepinita

The command run is git --git-dir=/home/user/Code/git/llvm/.git --work-tree=/home/user/Code/git/llvm status --branch --porcelain. Are those directories correct? (Do they exist?)

But it seems the command doesn't have any output, not on stdout nor stderr, otherwise it would have been logged.

Can you verify that there's indeed no output when running the command manually?

PS: I assume you have a git version lower than 1.8.5. What version do you have?

jaspernbrouwer avatar Jun 17 '15 19:06 jaspernbrouwer

Yes there is no output. If I touch a file or change something then no error is returned and i can actually see an output segment. Yes my git version is lower than 1.8.5, it is 1.7.9.5.

gepinita avatar Jun 17 '15 19:06 gepinita

Better, can you run this command from the root of your filesystem (cd /): git --git-dir=/home/user/Code/git/llvm/.git --work-tree=/home/user/Code/git/llvm status --branch --porcelain

And can you run this command from within the working copy (cd /home/user/Code/git/llvm): git status --branch --porcelain

jaspernbrouwer avatar Jun 17 '15 19:06 jaspernbrouwer

Because I'm curious: What's the reason you have such an old version of git? (current latest is v2.4.4)

jaspernbrouwer avatar Jun 17 '15 19:06 jaspernbrouwer

Ok. For both returns no output. But after all it's because the version of my git being old. I updated to last one and it works fine.

gepinita avatar Jun 17 '15 19:06 gepinita

I'm glad your immediate issue is resolved!

I'm going to keep this open, see if I can get a hold of an old git version to investigate this further. I have a vague recollection of a certain Linux distribution that was stuck on a lower version, and don't want to require any higher version than absolutely needed.

jaspernbrouwer avatar Jun 17 '15 19:06 jaspernbrouwer

Since I haven't had time to dove deeper into this issue I'm going to close it. Feel free to reopen (hopefully with additional info) if the problem arises again.

jaspernbrouwer avatar May 10 '16 20:05 jaspernbrouwer

This issue is affecting me too; I've been using this package in my powerline config on local machine and it's working great, but I just tried copying my setup onto a server I use at work, and am encountering the same exception. Unfortunately I'm stuck with git 1.7 on that server (it's on an older-but-still-supported LTS release of Ubuntu).

What information would be useful to provide?

I get the IndexError: pop from empty list exception in a checkout that is clean, but in a checkout with uncommited modifications there is no error but I see something like this in the gitstatus segment:

M .config/powerline/themes/shell/default.json

Which is just the first line of the output of git --git-dir=/home/benme/.git --work-tree=/home/benme status --branch --porcelain.

Oh, I did set the use_dash_c argument to false, as described in the usage guide.

I ran a similar git status --branch --porcelain command on my workstation with a newer git, and the first line is instead something like:

## nixos...origin/nixos

The Python code indicated by the IndexError exception is:

branch, detached, behind, ahead = self.parse_branch(status.pop(0))

Looking at parse_branch it's obviously depending on the header line describing the branch; it appears that header line is not being produced by the older git, so it misidentifies the first line of git's output about modified files as identifying the branch, and if there aren't any lines of output at all the status.pop(0) fails completely.

cumber avatar Jun 15 '16 03:06 cumber

This is very useful information indeed. I've got a much better picture of what's happening with older versions. I might be able to provide a fix without needing to get hold of such a version. I'll look into at when I have some time to spare!

jaspernbrouwer avatar Jun 15 '16 07:06 jaspernbrouwer

Great; I'll be happy to test a potential fix if you implement one.

cumber avatar Jun 15 '16 07:06 cumber

To echo @cumber, git status --porcelain --branch does not include the branch name, though git status --short --branch does. This was amended in git 1.7.10.3 https://github.com/git/git/commit/d4a6bf1fb64d904e210fbf7c5b330b06438a5bd5

justsh avatar Oct 31 '16 22:10 justsh

I attempted to reproduce the error on Ubuntu 12.04 LTS which shipped git 1.7.9.5, but was unable. The prompt seems to work fine, and the branch name is displayed correctly, even with a git status --branch --porcelain command that has no output.

Please reopen if this is still an issue that some users are encountering.

jcharaoui avatar Oct 02 '22 19:10 jcharaoui