rscherf / GitLink

Open your Sublime Text files on GitHub, Bitbucket, Gitlab or Codebase
http://ryan.sc
34 stars 25 forks source link

Git Version Error ("ValueError: need more than 1 value to unpack") #26

Closed KyleKing closed 2 years ago

KyleKing commented 2 years ago

On the latest version of GitLink, I see the below error

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python33/sublime_plugin.py", line 1488, in run_
    return self.run(edit, **args)
  File "/Users/kyleking/Library/Application Support/Sublime Text/Installed Packages/GitLink.sublime-package/GitLink.py", line 88, in run
ValueError: need more than 1 value to unpack

The issue is that my version of git is too old 2.20.1 (>2.22)

> git branch --show-current                                                                                                                                                                          
error: unknown option `show-current'
usage: git branch [<options>] [-r | -a] [--merged | --no-merged]
   or: git branch [<options>] [-l] [-f] <branch-name> [<start-point>]
   or: git branch [<options>] [-r] (-d | -D) <branch-name>...
   or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch>
   or: git branch [<options>] (-c | -C) [<old-branch>] <new-branch>
   or: git branch [<options>] [-r | -a] [--points-at]
   or: git branch [<options>] [-r | -a] [--format]
...

The error should have likely been caught at git branch ..., but it looks like neither err nor out.returncode are checked:

https://github.com/rscherf/GitLink/blob/e2e7c412630246efc86de4fe71192f15bf11209e/GitLink.py#L38-L40

It may also be beneficial to validate the branch name:

https://github.com/rscherf/GitLink/blob/e2e7c412630246efc86de4fe71192f15bf11209e/GitLink.py#L51-L52

You could alternatively replace the --show-current command with: git symbolic-ref --short HEAD which is backward compatible (not that it needs to be) and would work with submodules

For me, switching to git managed by homebrew (brew install git) fixed the issue and GitLink now works, but there might be some minor changes that could better handle errors. I would be happy to submit a PR!

Update: updated a few times for clarity!

wburningham commented 2 years ago

I also encountered this error when running git version 2.34.0

KyleKing commented 2 years ago

I would be happy to submit a PR if you would be open to changes for this

rscherf commented 2 years ago

Sounds good to me! 👍

On Mon, Feb 7, 2022 at 8:11 PM Kyle King @.***> wrote:

I would be happy to submit a PR if you would be open to changes for this

— Reply to this email directly, view it on GitHub https://github.com/rscherf/GitLink/issues/26#issuecomment-1032139056, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSKRHN64KCXNKHDHRH3BDU2B3ULANCNFSM5MLAJVSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>