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

Failed to run external command: git, args: [branch --merged origin/] #79

Closed
tnorthcutt opened this issue Oct 19, 2022 · 17 comments · Fixed by #88
Closed

Failed to run external command: git, args: [branch --merged origin/] #79

tnorthcutt opened this issue Oct 19, 2022 · 17 comments · Fixed by #88

Comments

@tnorthcutt
Copy link

Describe the bug
When I install this extension and try to run it with gh poi --dry-run, I receive the following output:

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
failed to run external command: git, args: [branch --merged origin/]
exit status 128

Your Environment

  • OS: macOS 12.6
  • gh (Check with gh --version): 2.18.0
  • gh-poi (Check with gh ext ls): v0.6.3
  • git: 2.37.0 (Apple Git-136)

This seems to be the case regardless of which repo I run it in.

If I run git branch --merged origin or git branch --merged origin/, I get this output:

fatal: malformed object name origin

I'm not sure how to further debug this, but I'm happy to help however I can!

@seachicken
Copy link
Owner

Thanks for reporting😃
Looks like you are not getting the default branch name.
What does the following return on the target repository?

gh repo view --json defaultBranchRef

@tnorthcutt
Copy link
Author

@seachicken thanks for the reply! Here's what I get:

» gh repo view --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  }
}

@seachicken
Copy link
Owner

Perhaps something is wrong with getting hostname or repoName.

"repo", "view", hostname + "/" + repoName,

  1. run git remote -v to display origin address
    # for example:
    origin  git@github.com:seachicken/gh-poi.git (fetch)
    origin  git@github.com:seachicken/gh-poi.git (push)
  2. run ssh -T -G {hostname (e.g. github.com)} | grep hostname to see if hostname can be obtained.
  3. rerun gh repo view {hostname}/{repoName (e.g. seachicken/gh-poi)} --json defaultBranchRef

@tnorthcutt
Copy link
Author

Thank you! Here's what I get – I'm not sure I did exactly what you were asking; please let me know if I've messed up anywhere 😊

» git remote -v                       
origin	git@github.com:apiabroad/portal-student.git (fetch)
origin	git@github.com:apiabroad/portal-student.git (push)

» ssh -T -G github.com | grep hostname
hostname ssh.github.com
canonicalizehostname false

» gh repo view ssh.github.com/apiabroad/portal-student --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  }
}

@seachicken
Copy link
Owner

It may have something to do with being able to get ssh.github.com. (I can get github.com in my environment.)

  1. Does the following command not result in an error?
gh api --hostname ssh.github.com repos/apiabroad/portal-student --silent

related code:

"api",

  1. Also, does ~/.ssh/config have this setting in your environment?
    https://docs.github.com/ja/enterprise-cloud@latest/authentication/troubleshooting-ssh/using-ssh-over-the-https-port#enabling-ssh-connections-over-https

@tnorthcutt
Copy link
Author

Hmm, that does result in an error:

» gh api --hostname ssh.github.com repos/apiabroad/portal-student --silent
Get "https://api.ssh.github.com/repos/apiabroad/portal-student": x509: “*.github.com” certificate name does not match input

I do have this in my ~/.ssh/config:

Host github.com
	Hostname ssh.github.com
	Port 443
	ForwardAgent yes

@seachicken
Copy link
Owner

ssh.github.com is now supported. https://github.com/seachicken/gh-poi/releases/tag/v0.6.4
Can you try it?
gh ext upgrade poi

@tnorthcutt
Copy link
Author

Unfortunately I still get this output after upgrading:

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
failed to run external command: git, args: [branch --merged origin/]
exit status 128

@seachicken
Copy link
Owner

Thanks for checking 🙂
Added error handling when GitHub API response cannot be parsed. You may get a different error message after updating.
gh ext upgrade poi https://github.com/seachicken/gh-poi/releases/tag/v0.6.6

Maybe the response with all the options set can't be parsed.
gh repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef

@tnorthcutt
Copy link
Author

tnorthcutt commented Oct 31, 2022

Interesting, a new error!

Does this provide more/better information?

» gh ext upgrade poi
✓ Successfully upgraded extension poi

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
error unmarshaling response: invalid character '\x1b' looking for beginning of value

» gh repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  },
  "name": "portal-student",
  "owner": {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "login": "apiabroad"
  },
  "parent": null
}

@seachicken
Copy link
Owner

I successfully parsed the JSON you taught me. Maybe another JSON is being retrieved, so if you could let me know the result, I might be able to solve the problem 🙂

gh ext upgrade poi
gh poi --debug | grep "repo view"

@tnorthcutt
Copy link
Author

Thank you! Here's what I get after upgrading:

» gh poi --debug | grep "repo view"
error unmarshaling response: invalid character '\x1b' looking for beginning of value
run gh [repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef] -> {

And here's the full output, in case it's helpful:

» gh poi --debug                   
run git [remote -v] -> origin	git@github.com:apiabroad/portal-student.git (fetch)
origin	git@github.com:apiabroad/portal-student.git (push)

run ssh [-T -G github.com] -> *****
run gh [repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef] -> {
  "defaultBranchRef": {
    "name": "staging"
  },
  "name": "portal-student",
  "owner": {
    "id": "MDEyOk9yZ2FuaXphdGlvbjE0ODgwNDYy",
    "login": "apiabroad"
  },
  "parent": null
}

✕ Fetching pull requests...
error unmarshaling response: invalid character '\x1b' looking for beginning of value

@seachicken
Copy link
Owner

Perhaps your environment was not decoding the JSON because the output of the gh pr view included color char codes.
I have created a version that works without including the color char code, so if possible, could you please help me confirm that it works?
#88

gh ext remove poi
gh ext install seachicken/gh-poi --pin v0.7.2-pre0

@tnorthcutt
Copy link
Author

That works!! Magnificent 🎉

thor-yes-excited

@seachicken
Copy link
Owner

Yay!!! Thank you 😍
I'll release it later.

@seachicken
Copy link
Owner

@tnorthcutt I released v0.7.2! To remove version pinning by --pin, run gh ext upgrade poi --force .

@tnorthcutt
Copy link
Author

@seachicken thank you!

Just FYI gh doesn't allow upgrading pinned extensions:

» gh ext upgrade poi --force                        
X Failed upgrading extension poi: pinned extensions can not be upgraded

So I just did gh ext remove poi and then gh ext install seachicken/gh-poi and that worked great!

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

Successfully merging a pull request may close this issue.

2 participants