read-only-coding icon indicating copy to clipboard operation
read-only-coding copied to clipboard

Quote paths when determining GitHub URL

Open Bersaelor opened this issue 7 years ago • 6 comments
trafficstars

Thank you for the idea, it would be so great if I could open code-pieces directly via Xcode -> Github.

I get the following warning when trying your script (Via Xcode-> Services -> Open Selection in Github: screen shot 2018-09-03 at 16 46 57

Bersaelor avatar Sep 03 '18 14:09 Bersaelor

Hi @Bersaelor, based on the URL in the error message, it looks like the workflow was unable to determine the URL of a remote to open and was additionally unable to come up with a path to a file within the repository. The workflow currently requires your clone to have a remote named origin (#3) that has an HTTPS URL (#4). Could that be the issue in this case?

1ec5 avatar Sep 04 '18 04:09 1ec5

So my remote was [email protected]:Bersaelor/project.git not https. (this seems to be the default when cloning a project via source-tree). I changed it manually so that:

$ git remote -v
origin	https://github.com/Bersaelor/project.git (fetch)
origin	https://github.com/Bersaelor/project.git (push)

and I still get the same error message.

Then I tried a different project (a public repo this time) and it worked even with [email protected]:Bersaelor/KDTree.git.

90% of the projects I'm working on are private so I didn't notice before.

That means the extension only works with public repos?

Bersaelor avatar Sep 04 '18 09:09 Bersaelor

Then I tried a different project (a public repo this time) and it worked even with [email protected]:Bersaelor/KDTree.git.

Come to think of it, SSH URLs should be converted to HTTPS URLs on the fly: https://github.com/1ec5/read-only-coding/issues/4#issuecomment-418301726.

That means the extension only works with public repos?

It should work with clones of private GitHub repositories, not just public ones. I use the workflow daily with both public and private repositories.

It seems like the workflow is simply unable to get any results out of git for some reason. Is your default shell Bash or something else? If you run these Bash commands, substituting the absolute file path for $1, what gets echoed out?

https://github.com/1ec5/read-only-coding/blob/bc136b778fb923e064f5f7dde3799fbe78c17626/Open%20Selection%20in%20GitHub.workflow/Contents/document.wflow#L403-L413

1ec5 avatar Sep 04 '18 09:09 1ec5

[konrad@iMac DV Bespoke]$ REPO_URL=$(git remote get-url origin)
[konrad@iMac DV Bespoke]$ HASH=$(git rev-parse HEAD)
[konrad@iMac DV Bespoke]$ cd $(git rev-parse --show-toplevel)
cd: no such file or directory: Bespoke Bespoke
[konrad@iMac DV Bespoke]$ REPO_RELATIVE_PATH=$(git ls-files "$1")
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths
[konrad@iMac DV Bespoke]$ git rev-parse --show-toplevel
/Users/konrad/DV Bespoke

Bersaelor avatar Sep 04 '18 09:09 Bersaelor

Ah, you have a space in the path to your file. The Bash script inside this workflow needs more quoting, apparently. Thanks for spotting this issue!

1ec5 avatar Sep 04 '18 09:09 1ec5

Yup, my projects name is DV Bespoke and when cloning that will be the folder name.

It just so happened that all the private repos I tried had blankspaces in their names.

Bersaelor avatar Sep 04 '18 09:09 Bersaelor