# Buggy code
def _eval_repo_url(repo_url):
    """Allow passing short GitHub style URLs"""
    if not repo_url:
        raise Exception("No valid repo_url provided or could be inferred.")
    if repo_url.startswith("file://"):
        return repo_url
    else:
        if len(repo_url.split("/")) == 2 and "git@" not in repo_url:
            url = "https://github.com/{}".format(repo_url)
        else:
            url = repo_url
        return url if url.endswith(".git") else "{}.git".format(url)


# Traceback (git.exc.GitCommandError)
ubuntu@st2-local:~$ st2 pack install ssh://<user@host>/AutomationStackStorm

[       failed       ] download pack

id: 595525a6a5fb1d0755645a1e
action.ref: packs.install
parameters:
packs:
- ssh://<user@host>/AutomationStackStorm
status: failed
error: Traceback (most recent call last):
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 259, in <module>
obj.run()
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 155, in run
output = action.run(**self._parameters)
File "/opt/stackstorm/packs/packs/actions/pack_mgmt/download.py", line 75, in run
verifyssl=verifyssl, ref=pack_version)
File "/opt/stackstorm/packs/packs/actions/pack_mgmt/download.py", line 102, in _clone_repo
repo = Repo.clone_from(repo_url, temp_dir)
File "/opt/stackstorm/st2/lib/python2.7/site-packages/git/repo/base.py", line 942, in clone_from
return cls._clone(git, url, to_path, GitCmdObjectDB, progress, **kwargs)
File "/opt/stackstorm/st2/lib/python2.7/site-packages/git/repo/base.py", line 897, in _clone
finalize_process(proc, stderr=stderr)
File "/opt/stackstorm/st2/lib/python2.7/site-packages/git/util.py", line 341, in finalize_process
proc.wait(**kwargs)
File "/opt/stackstorm/st2/lib/python2.7/site-packages/git/cmd.py", line 292, in wait
raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git clone -v ssh://<user@host>/AutomationStackStorm.git /root/<hash>
stderr: 'Cloning into '/root/<hash>'...

Your Git command did not succeed.
Details:
TF401019: The Git repository with name or identifier AutomationStackStorm.git does not exist or you do not have permissions for the operation you are attempting.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
'

traceback: None
failed_on: download pack
start_timestamp: 2017-06-29T16:07:02.112809Z
end_timestamp: 2017-06-29T16:07:08.565932Z
+--------------------------+---------------------+---------------+----------------+-----------------+
| id                       | status              | task          | action         | start_timestamp |
+--------------------------+---------------------+---------------+----------------+-----------------+
| 595525a6a5fb1d0559d30ab4 | failed (6s elapsed) | download pack | packs.download | Thu, 29 Jun     |
|                          |                     |               |                | 2017 16:07:02   |
|                          |                     |               |                | UTC             |
+--------------------------+---------------------+---------------+----------------+-----------------+

# Fixed code
def _eval_repo_url(repo_url):
    """Allow passing short GitHub style URLs"""
    if not repo_url:
        raise Exception("No valid repo_url provided or could be inferred.")
    if repo_url.startswith("file://"):
        return repo_url
    else:
        if len(repo_url.split("/")) == 2 and "git@" not in repo_url:
            url = "https://github.com/{}".format(repo_url)
        else:
            url = repo_url
        return url