diff options
author | Emanuele Aina <emanuele.aina@collabora.com> | 2021-04-05 22:43:16 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2021-09-30 16:36:03 +0200 |
commit | f90e4f84048a99ec228d23b617c3661a805bbaf3 (patch) | |
tree | dccedfcd90cd06eee7f27adc1a26e392f1cf3277 /gbp/git | |
parent | 26d6cebc34b94360e27c428ef91ecca30a48d200 (diff) |
Fix import-dsc on empty repo if defaultBranch!=master
When importing a dsc on a empty repository when `ìnit.defaultBranch` is
set to something like `main` in `~/.gitconfig` we failed with:
gbp:debug: ['git', 'update-ref', '-m', 'gbp: Import Upstream version 0.5.10.2', 'refs/heads/master', '95172aee8d1a4e6c69494e4f158f904111710168']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/main']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/main']
gbp:debug: ['git', 'branch', '-m', 'None', 'debian/buster']
gbp:error: Git command failed: Error running git branch: error: refname refs/heads/None not found
fatal: Branch rename failed
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/gbp-0.9.22-py3.9.egg/gbp/scripts/import_dsc.py", line 519, in main
commit = import_upstream(repo, sources[0], dsc, options)
File "/usr/local/lib/python3.9/dist-packages/gbp-0.9.22-py3.9.egg/gbp/scripts/import_dsc.py", line 269, in import_upstream
repo.rename_branch(repo.branch, options.debian_branch)
File "/usr/local/lib/python3.9/dist-packages/gbp-0.9.22-py3.9.egg/gbp/git/repository.py", line 333, in rename_branch
self._git_command("branch", args.args)
File "/usr/local/lib/python3.9/dist-packages/gbp-0.9.22-py3.9.egg/gbp/git/repository.py", line 245, in _git_command
raise GitRepositoryError("Error running git %s: %s" % (command, detail.decode().strip()))
gbp.git.repository.GitRepositoryError: Error running git branch: error: refname refs/heads/None not found
fatal: Branch rename failed
That's because we created the commit on `refs/heads/master` and then
tried to rename it from `refs/heads/main`.
To avoid that, if the repository is empty look at the name of the
current branch as reported by the symbolic ref pointed by `HEAD`.
Closes: #906600
Signed-off-by: Emanuele Aina <emanuele.aina@collabora.com>
Diffstat (limited to 'gbp/git')
-rw-r--r-- | gbp/git/repository.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 63957789..48d00533 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1545,7 +1545,12 @@ class GitRepository(object): raise else: # empty repo cur = None - branch = 'master' + out, _, ret = self._git_inout('symbolic-ref', ['HEAD'], + capture_stderr=True) + if ret: + raise GitRepositoryError("Currently not on a branch") + ref = out.decode().split('\n')[0] + branch = ref[len('/refs/heads'):] # Build list of parents: parents = [] |