0

I have searched in google, they say "git ls-remote git-url" can say whether git repo exists or not.

But i have a problem when use this command to check github unexisting https git url.

for example, when I run below command, it will require input username and password.

$ git ls-remote https://github.com/grant/noexisted.git

I only want to check whether the repo exists or not, and I call "git ls-remote" command in ruby code, so how to skip this auto shell prompt?

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
Grant Chen
  • 375
  • 2
  • 4
  • 14

1 Answers1

3

Why not just make an HTTP request, and look for a 404?

For example, you can use the wget command-line utility:

$ wget https://github.com/grant/noexisted.git --no-check-certificate -o /dev/null
$ echo ?

This prints 8, while

$ wget https://github.com/mikeobrien/HidLibrary --no-check-certificate -o /dev/null
$ echo $?

this prints 0 (success).

I'm not familiar with Ruby, but I'm sure it would be trivial to make the HTTP request and check for a 404 (not found) or 200 (success).

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Thanks. Yes, it can work. As the this repo url is input by user, can be any value. if just use git ls-remote one command to check will be more better. If use your suggestion, i will need check url is http repo url or other url(ssh or git). If don't have any better way, i will use your suggestion. – Grant Chen Mar 17 '14 at 09:36