dynamist/subgit

Cloning into bare git repo fails

Grokzen opened this issue · 2 comments

It is currently not possible to add a repo that is bare and dont have any refs on the remote side. It fails out with the error fatal: Remote branch master not found in upstream origin

Investigate if it is possible to determine if the repo is bare or not. Otherwise a new solution has to be thought up on how to deal with this case as it must be supported.

DEBUG: Repo update - all
Are you sure you want to update the following repos "myrepo"
(y/n) << y
Traceback (most recent call last):
  File "/home/nn/code/foobar/sgit/sgit/core.py", line 260, in update
    branch=revision['branch'],
  File "/home/nn/code/foobar/sgit/.venv/lib/python3.6/site-packages/git/repo/base.py", line 1017, in clone_from
    return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs)
  File "/home/nn/code/foobar/sgit/.venv/lib/python3.6/site-packages/git/repo/base.py", line 958, in _clone
    finalize_process(proc, stderr=stderr)
  File "/home/nn/code/foobar/sgit/.venv/lib/python3.6/site-packages/git/util.py", line 328, in finalize_process
    proc.wait(**kwargs)
  File "/home/nn/code/foobar/sgit/.venv/lib/python3.6/site-packages/git/cmd.py", line 408, in wait
    raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git clone --branch=master -v git@gitlab.com:foobar/myrepo.git /home/nn/code/foobar/sysrepo/myrepo
  stderr: 'Cloning into '/home/nn/code/foobar/sysrepo/myrepo'...
fatal: Remote branch master not found in upstream origin
fatal: the remote end hung up unexpectedly
'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nn/code/foobar/sgit/sgit/cli.py", line 185, in cli_entrypoint
    exit_code = run(cli_args, sub_args)
  File "/home/nn/code/foobar/sgit/sgit/cli.py", line 171, in run
    retcode = core.update(repo)
  File "/home/nn/code/foobar/sgit/sgit/core.py", line 264, in update
    raise SgitException(f'Clone "{name}" failed, exception: {e}')
sgit.exceptions.SgitException: Clone "myrepo" failed, exception: Cmd('git') failed due to: exit code(128)
  cmdline: git clone --branch=master -v git@gitlab.com:foobar/myrepo.git /home/nn/code/foobar/sysrepo/myrepo
  stderr: 'Cloning into '/home/nn/code/foobar/sysrepo/myrepo'...
fatal: Remote branch master not found in upstream origin
fatal: the remote end hung up unexpectedly
'
> /home/nn/code/foobar/sgit/sgit/core.py(264)update()
-> raise SgitException(f'Clone "{name}" failed, exception: {e}')

With the following .sgit.yml file

repos:
  bare:
    clone-url: git@gitlab.com:dynamist/sgit-bare-repo.git
    revision:
      branch: master

you will get the following output from the initial update and future updates

(sgit) ➜  sgit git:(master) ✗ DEBUG=1 PDB=1 sgit -y update
DEBUG: Repo update - None
Are you sure you want to update the following repos "bare"
INFO: Automatically answer yes to question
Successfully cloned into bare git repo "bare" from remote server

(sgit) ➜  sgit git:(master) ✗ sgit update
DEBUG: Repo update - None
Are you sure you want to update the following repos "bare"
(y/n) << y
TODO: Parse for any changes...
DEBUG: Handling branch update case
Exception type : BadName
EXCEPTION MESSAGE: Ref 'origin/master' did not resolve to an object
To get more detailed exception set environment variable 'DEBUG=1'
To PDB debug set environment variable 'PDB=1'

Note that it is intended for the second sgit update to fail as the remote branch origin/master do not yet exists in a bare git repo.