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

Git commit breaks sometimes if submodules exist #229

Closed
alichtman opened this issue Sep 18, 2019 · 3 comments
Closed

Git commit breaks sometimes if submodules exist #229

alichtman opened this issue Sep 18, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@alichtman
Copy link
Owner

alichtman commented Sep 18, 2019

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.

@alichtman alichtman added the bug Something isn't working label Sep 18, 2019
@alichtman alichtman changed the title Git commit breaks if subbmodules exist Git commit breaks if submodules exist Sep 18, 2019
@alichtman alichtman changed the title Git commit breaks if submodules exist Git commit breaks sometimes if submodules exist Sep 18, 2019
@alichtman
Copy link
Owner Author

alichtman commented Sep 18, 2019

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

@alichtman
Copy link
Owner Author

alichtman commented Sep 23, 2019

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.

@Kabouik
Copy link

Kabouik commented Jul 11, 2021

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

alichtman added a commit that referenced this issue Oct 9, 2023
I think this bug was the longest standing bug in any of my projects, ever. I opened this bug report (#229) over 4 years ago!

It's really not that complicated of a fix, either. I'm disappointed that this took me so long to fix.

 `shallow-backup` will only support a nested `dotfiles` repo. If it exists, prompt the user to make a commit in the submodule first to avoid a failed commit on the parent repo later.

Fix #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants