Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more output for Git errors on push #751

Merged
merged 1 commit into from
Mar 9, 2023
Merged

Conversation

psy-q
Copy link
Contributor

@psy-q psy-q commented Mar 9, 2023

This provides Git's stderr output when errors occur trying to push catalogs. Previously, only the exit code was returned, which usually is simply 1 and not very specific.

Background

The default branch in most Git hosting environments is called main now, but Commodore seems to expect the remote HEAD to be master. Trying a commodore catalog compile --push on a catalog repository with main as default branch will fail with "error: src refspec master does not match any...".

It would be cleverer to make Commodore read the default branch name from the remote repo and use that instead. But in the meantime, having more error output at least makes it possible to narrow down the cause of a push problem.

Problems

The stderr output seems to be truncated (by the GitRepo module?). I couldn't figure out how to get the whole output without the truncated first line. Subsequent lines seem OK?

Update: Actually, this may also be a new issue in Git itself. When pushing from the command-line, it also truncates after "does not match any" for me.

Checklist

  • Keep pull requests small so they can be easily reviewed.
  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency, internal
    as they show up in the changelog

Signed-off-by: Ramón Cahenzli <ramon.cahenzli@vshn.ch>
@psy-q psy-q added the enhancement New feature or request label Mar 9, 2023
@psy-q psy-q requested a review from a team as a code owner March 9, 2023 08:55
Copy link
Member

@simu simu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

We do try to identify the remote default branch name (cf.

def _default_version(self) -> str:
"""
Find default branch of the remote
"""
try:
version = self._repo.remote().refs["HEAD"].reference.name
except IndexError:
try:
self._repo.git.remote("set-head", "origin", "--auto")
version = self._repo.remote().refs["HEAD"].reference.name
except GitCommandError:
# If we don't have a remote HEAD, we fall back to creating a master
# branch.
version = f"{self._remote_prefix()}master"
return version.replace(self._remote_prefix(), "", 1)
), but still fall back to master when the remote doesn't have any commits and therefore doesn't have a HEAD. We currently fall back to master, because there's a bunch of tooling in Project Syn which doesn't work well with main as the default branch name (e.g. component GitHub actions)

@psy-q
Copy link
Contributor Author

psy-q commented Mar 9, 2023

Ah, I did notice GitLab doesn't even show any UI for picking the default branch after project creation. It took me a while to figure out it needs an actual ref to point to for that to work.

@psy-q psy-q merged commit b0846c3 into master Mar 9, 2023
@psy-q psy-q deleted the more_git_error_output branch March 9, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants