alichtman / shallow-backup

Git-integrated backup tool for macOS and Linux devs.
MIT License
1.22k stars 248 forks source link

Support default branches other than `master` #305

Closed oWretch closed 2 years ago

oWretch commented 2 years ago

I created a new repository to use shallow backup, and GitHub created the default branch as main.

When I attempt to push the backup to GitHub, it fails as it tries to configure the upstream branch as master which doesn't exist.

Pushing to master: git@github.com:oWretch/shallow_backup.git...
Traceback (most recent call last):
  File "/opt/homebrew/bin/shallow-backup", line 33, in <module>
    sys.exit(load_entry_point('shallow-backup==5.1', 'console_scripts', 'shallow-backup')())
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/shallow_backup/__main__.py", line 132, in cli
    git_add_all_commit_push(repo, "full_backup")
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/shallow_backup/git_wrapper.py", line 111, in git_add_all_commit_push
    repo.git.push("--set-upstream", "origin", "master")
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/git/cmd.py", line 638, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/git/cmd.py", line 1183, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/opt/homebrew/Cellar/shallow-backup/5.1/libexec/lib/python3.10/site-packages/git/cmd.py", line 983, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push --set-upstream origin master
  stderr: 'error: src refspec master does not match any
error: failed to push some refs to 'github.com:oWretch/shallow_backup.git''
alichtman commented 2 years ago

https://github.com/alichtman/shallow-backup/blob/b14140dc04d0ea6733320623b81eacabf00d7dbc/shallow_backup/git_wrapper.py#L111

The problem is right here. Maybe we have this branch be set in the config file?