Push error with recent version of git
Issue
Recent versions of git set the principal branch name to main
instead of the former master
. This is not managed out of the box by sharelatex. Executing the command git slatex push
generates the following exception:
DEBUG:git.cmd:Popen(['git', 'checkout', 'master'], cwd=/path/to/the/project, universal_newlines=False, shell=None, istream=None)
Traceback (most recent call last):
File "/opt/venv/venv-sharelatex/bin/git-slatex", line 8, in <module>
sys.exit(cli())
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/sharelatex/cli.py", line 440, in push
_pull(repo, client, project_id)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/sharelatex/cli.py", line 256, in _pull
git.checkout("master")
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/git/cmd.py", line 545, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/git/cmd.py", line 1014, in _call_process
return self.execute(call, **exec_kwargs)
File "/opt/venv/venv-sharelatex/lib/python3.8/site-packages/git/cmd.py", line 825, in execute
raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
cmdline: git checkout master
stderr: 'error: pathspec 'master' did not match any file(s) known to git'
Workaround
A temporal workaround is to change the name of the branch to master locally:
git checkout main && git branch -m master
Expected behavior
- Sharelatex gets the original name of principal branch set locally and use it as parameter while pushing; or
- Add a variable in the local configuration of git to set the name of local/remote branches used by sharelatex