Cannot get git ls-remote list and no error at stdout

1.7k views Asked by At

I'm executing git ls-remote ssh://git@git_repo:port * in two different computers under same network, one Linux another Windows, and on Windows I'm getting the list but on Linux not. No error at all just and empty list on Linux.

Both has the SSH key added to the remote repository and both are able to clone the repository.

Update 1:

Windows Git version: 2.19.2.windows.1

Linux Git version: 2.7.4

Update 2:

The repository is in Gerrit.

Update 3:

I'm facing this problem using the Jenkins plugin Extended Choice Parameter plugin. It has no change since 2016. Any workaround for this would be also an answer.

Any idea?

1

There are 1 answers

0
torek On BEST ANSWER

You probably should use:

git ls-remote ssh://git@git_repo:port

without any suffix, as it defaults to listing everything.

You can use:

git ls-remote ssh://git@git_repo:port '*'

(or the same with double quotes—one or both of these may work on Windows as well). In a Unix/Linux-style command shell, the shell will replace * with a list of all the files in the current directory before running the command, unless you protect the asterisk from the shell.

You can also use a single backlash:

git ls-remote ssh://git@git_repo:port \*

as there are a lot of ways to protect individual characters from shells. The rules get a little complicated, but in general, single quotes are the "most powerful" quotes, while double quotes quote glob characters1 but not other expansions.2 Backslashes quote the immediate next character if you're not already inside quotes (the behavior of backslash within double quotes varies in some shells).


1The glob characters are *, [, and ?. After [, characters inside the glob run to the closing ]. So echo foo[abc] looks for files named fooa, foob, and fooc. Note that . is generally not special: foo.* matches only files whose names start with foo., i.e., including the period: a file named foo does not start with foo., only with foo, and is not matched.

Globs are very different from regular expressions: in regular expressions, . matches any character (like ? does in glob) and asterisk means "repeat previous match zero or more times", so that glob * and regular-expression .* are similar. (In regular expression matches, we also need to consider whether the expression is anchored. Globs are always anchored so that the question does not arise.)

2Most expansions occur with dollar sign $, as in $var or ${var} or $(subcommand), but backquotes also invoke command substitution, as in echo `echo bar`.