alichtman / shallow-backup

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

Catch git push error and print a helpful message #339

Open alichtman opened 6 months ago

alichtman commented 6 months ago

Maybe: $ git push failed! You probably need to $ git pull first.

Successful commit.
Pushing to remote: git@github.com:alichtman/dotfiles[origin/main]...
Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/bin/shallow-backup", line 8, in <module>
    sys.exit(cli())
    │        └ <click.core.Command object at 0x7f5d0c1ca090>
    └ <module 'sys' (built-in)>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
           │          │       └ {}
           │          └ ()
           └ <click.core.Command object at 0x7f5d0c1ca090>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
         │           └ <click.core.Context object at 0x7f5d0d16dd50>
         └ <click.core.Command object at 0x7f5d0c1ca090>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           │          │                └ <click.core.Context object at 0x7f5d0d16dd50>
           │          └ <click.core.Command object at 0x7f5d0c1ca090>
           └ <click.core.Context object at 0x7f5d0d16dd50>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
           │         │       └ {'backup_dots_flag': True, 'add_dot': None, 'backup_all_flag': False, 'backup_configs_flag': False, 'backup_fonts_flag': False, ...
           │         └ ()
           └ <function cli at 0x7f5d0c1ce3e0>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/shallow_backup/__main__.py", line 252, in cli
    handle_separate_git_dir_in_dotfiles(dotfiles_path, dry_run)
    │                                   │              └ False
    │                                   └ '/home/alichtman/shallow-backup/dotfiles'
    └ <function handle_separate_git_dir_in_dotfiles at 0x7f5d0c167920>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/shallow_backup/git_wrapper.py", line 104, in handle_separate_git_dir_in_dotfiles
    git_add_all_commit_push(
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/shallow_backup/git_wrapper.py", line 207, in git_add_all_commit_push
    repo.git.push("--set-upstream", "origin", "HEAD")
    └ <git.repo.base.Repo '/home/alichtman/shallow-backup/dotfiles/.git'>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/git/cmd.py", line 739, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   │                  │      │       └ {}
                                   │                  │      └ ('--set-upstream', 'origin', 'HEAD')
                                   │                  └ 'push'
                                   └ <git.cmd.Git object at 0x7f5d0c1dc0a0>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/git/cmd.py", line 1315, in _call_process
    return self.execute(call, **exec_kwargs)
           │            │       └ {}
           │            └ ['git', 'push', '--set-upstream', 'origin', 'HEAD']
           └ <git.cmd.Git object at 0x7f5d0c1dc0a0>
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/git/cmd.py", line 1110, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
          │               │                 │       │             └ b''
          │               │                 │       └ b"To github.com:alichtman/dotfiles\n ! [rejected]        HEAD -> main (non-fast-forward)\nerror: failed to push some refs to 'gi...
          │               │                 └ 1
          │               └ ['git', 'push', '--set-upstream', 'origin', 'HEAD']
          └ <class 'git.exc.GitCommandError'>
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push --set-upstream origin HEAD
  stderr: 'To github.com:alichtman/dotfiles
 ! [rejected]        HEAD -> main (non-fast-forward)
error: failed to push some refs to 'github.com:alichtman/dotfiles'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.'