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

Catch git push error and print a helpful message #339

Open
alichtman opened this issue Dec 10, 2023 · 0 comments
Open

Catch git push error and print a helpful message #339

alichtman opened this issue Dec 10, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@alichtman
Copy link
Owner

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

Successful commit.
Pushing to remote: [email protected]: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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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.'

@alichtman alichtman added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant