alichtman/shallow-backup

Git commit breaks sometimes if submodules exist

alichtman opened this issue · 3 comments

I have no idea why this just broke. I think this is a new change in git, as I know for sure this method worked until, like, today.

I was able to fix this error by committing the changes in my submodule, but I haven't fixed it programmatically yet.

The fix will likely be in the git_add_all_commit_push method with something like:

for submodule in repo.submodules:
	commit all the changes, yada yada yada

then do the rest of the things.

I'd like to be able to interactively decide on commit messages for the dotfiles submodule, so some thought needs to go into how to fix this.

:(

This will stay broken for a little bit until I figure out a good solution. A temporary fix would be downgrading your git version to 2.19? I think that version would work, but not sure.

For my workflow, this actually isn't breaking. It's just a nasty looking error.

shallow-backup -no_splash -dotfiles

Detected git repo.

##########
# DOTFILES
##########

Backing up dotfolders...
Backing up dotfiles...
Making new commit...
Traceback (most recent call last):
  File "/usr/local/bin/shallow-backup", line 11, in <module>
    load_entry_point('shallow-backup==2.5a0', 'console_scripts', 'shallow-backup')()
    └ <function load_entry_point at 0x108158290>
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
           │          │       └ {}
           │          └ ()
           └ <click.core.Command object at 0x1084522d0>
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
         │           └ <click.core.Context object at 0x1082c4950><click.core.Command object at 0x1084522d0>
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           │          │                └ <click.core.Context object at 0x1082c4950>
           │          └ <click.core.Command object at 0x1084522d0><click.core.Context object at 0x1082c4950>
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
           │         │       └ {'dotfiles': True, 'all': False, 'configs': False, 'delete_config': False, 'destroy_backup': False, 'fonts': False, 'new_path': ...
           │         └ ()
           └ <function cli at 0x1086cb290>
  File "/usr/local/lib/python3.7/site-packages/shallow_backup-2.5a0-py3.7.egg/shallow_backup/__main__.py", line 119, in cli
    git_add_all_commit_push(repo, 'dotfiles')
    │                       └ <git.Repo "/Users/alichtman/shallow-backup/.git"><function git_add_all_commit_push at 0x1086345f0>
  File "/usr/local/lib/python3.7/site-packages/shallow_backup-2.5a0-py3.7.egg/shallow_backup/git_wrapper.py", line 79, in git_add_all_commit_push
    repo.git.commit(m=COMMIT_MSG[message])
    │                 │          └ 'dotfiles'
    │                 └ {'fonts': 'Back up fonts.', 'packages': 'Back up packages.', 'configs': 'Back up configs.', 'all': 'Full back up.', 'dotfiles': ...
    └ <git.Repo "/Users/alichtman/shallow-backup/.git">
  File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 548, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   │                  │      │       └ {'m': 'Back up dotfiles.'}
                                   │                  │      └ ()
                                   │                  └ 'commit'<git.cmd.Git object at 0x1086b6a60>
  File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 1014, in _call_process
    return self.execute(call, **exec_kwargs)
           │            │       └ {}
           │            └ ['git', 'commit', '-m', 'Back up dotfiles.']
           └ <git.cmd.Git object at 0x1086b6a60>
  File "/usr/local/lib/python3.7/site-packages/git/cmd.py", line 825, in execute
    raise GitCommandError(command, status, stderr_value, stdout_value)
          │               │        │       │             └ b'On branch master\nChanges not staged for commit:\n\tmodified:   dotfiles (modified content)\n\nno changes added to commit'
          │               │        │       └ b''
          │               │        └ 1
          │               └ ['git', 'commit', '-m', 'Back up dotfiles.']
          └ <class 'git.exc.GitCommandError'>
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Back up dotfiles.
  stdout: 'On branch master
Changes not staged for commit:
        modified:   dotfiles (modified content)
shallow-backup on  master [!]
➜ ls 
      .git
      dotfiles
      .DS_Store
      .gitignore

shallow-backup on  master [!]
➜ ls dotfiles 
      .git
      .ssh
      .tmux
      .vim
      .aliases
      .ctags
      .gitconfig
      .gitignore
      .pypirc
      .radare2rc
      .shallow-backup
      .tmux.conf
      .vimrc
      .zfunctions
      .zlogin
      .zprofile
      .zshrc
      README.md

I've added two "fixes" for this. One takes care of the nasty looking error and the other is a flag that can be passed in to skip the commit. This works for my workflow since I don't really use any features of this except the dotfile backup for mirroring on GitHub.

$ python3 -m shallow_backup -dotfiles -separate_dotfiles_repo

The -separate_dotfiles_repo flag will skip the commit and give you a pointer back to this issue.

¯\(ツ)

If you have a better solution, I'm happy to hear about it.

For some reason, I'm having the same issue when I try to save only packages, with or without the -separate-dotfiles-repo flag. This would be my first use of shallow-backup so I cannot exclude that I'm doing something wrong.


##########
# PACKAGES
##########

Created directory: /home/user/shallow-backup/packages
Backing up brew packages list...
An error occurred while running: $ brew list
Backing up brew cask packages list...
An error occurred while running: $ brew cask list
Backing up gem packages list...
An error occurred while running: $ gem list
Backing up cargo packages list...
Backing up pip packages list...
Backing up pip3 packages list...
Backing up npm packages list...
Backing up Atom packages list...
An error occurred while running: $ apm list --installed --bare
Backing up VSCode packages list...
An error occurred while running: $ code --list-extensions --show-versions
Backing up macports packages list...
An error occurred while running: $ port installed requested
Backing up System Applications packages list...
Making new commit...
ERROR on Commit: ['git', 'commit', '-m', 'Back up packages.']


Issue tracked at: https://github.com/alichtman/shallow-backup/issues/229