Skip to content

Commit

Permalink
Ensure that catalog is initialized with branch master
Browse files Browse the repository at this point in the history
Before this commit, Commodore could fail to push the initial catalog for
a cluster if the user's Git config sets `init.defaultBranch`. The
observed error is:

```
 > Commiting changes...
 > Pushing catalog to remote...
Error: Failed to push to the catalog repository: Git exited with status code 1
The error reported was:
  stderr: 'error: src refspec master does not match any
error: failed to push some refs to 'ssh://<catalog repo>''
```

This error is caused because GitPython falls back to `init.defaultBranch`
when creating the catalog repo unless `initial_branch` is specified.

However, since Commodore unconditionally falls back to trying to push
`master` when no default branch can be identified in the remote repo
(e.g. empty catalog repo), the push then fails because we're trying to
push branch `master` which doesn't exist locally.

This isn't an issue for `commodore component new` and `commodore package
new` since we explicitly fall back to creating a `master` branch when
initializing the worktree for the new dependency.
  • Loading branch information
simu committed Feb 9, 2024
1 parent dc19c5c commit b71a28e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion commodore/gitrepo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
if not force_init and targetdir.exists():
self._repo = Repo(targetdir)
else:
self._repo = Repo.init(targetdir, bare=bare)
self._repo = Repo.init(targetdir, bare=bare, initial_branch="master")

if remote:
self.remote = remote
Expand Down

0 comments on commit b71a28e

Please sign in to comment.