TheLocehiliosan / yadm

Yet Another Dotfiles Manager
https://yadm.io/
GNU General Public License v3.0
4.94k stars 178 forks source link

yadm add not working #361

Closed tim-hilt closed 2 years ago

tim-hilt commented 2 years ago

Describe the bug

Running yadm add doesn't work anymore on my machine. A basic chain of yadm-commands looks like this for me:

$ yadm init
Initialized empty shared Git repository in /home/tim/.local/share/yadm/repo.git/

$ yadm add ~/.config/nvim/init.vim

$ yadm status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

$ yadm commit -m "Added init.vim"
On branch main

Initial commit

nothing to commit (create/copy files and use "git add" to track)

$ yadm status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

To reproduce

Can this be reproduced with the yadm/testbed docker image: No

Steps to reproduce the behavior:

I first noticed this, after I accidentally added my .config/nvim folder, which already is a git-repo. I think it got added as a git-submodule. I ran yadm rm --cached .config/nvim and then yadm add didn't have any effect anymore.

Expected behavior

yadm status shows added files, yadm commit commits staged files to the yadm-repo.

Environment

Additional context

The machine it doesn't work on is a Lenovo ThinkPad T14s Gen 1, which is powered by an AMD-Ryzen processor. It does work on my Lenovo ThinkPad X1 Carbon Gen 5, which is powered by an Intel core i7 processor.

Ironaki commented 2 years ago

I'm getting a similar bug with yadm 3.1.0.

It seems to be that when I doyadm add folder/file, if that folder is a git repo, folder/file won't be added.

tim-hilt commented 2 years ago

My actual problem is, that I can't add anything now! yadm add seems to just refuse to work.

Are you experiencing a similar kind of behavior?

rtbs-dev commented 2 years ago

Having this same problem. I ran yadm add .oh-my-zsh and then tried to undo (not realizing this was a git repo) with yadm rm --cached .oh-my-zsh. The preferred way is to add .oh-my-zsh/custom/, so I tried and nothing gets added. Even adding individual files from within that directory!

unsure how to get it working again after digging through the yadm config for a while. I am still able to add non-git stuff and git submodules just fine, however.

tim-hilt commented 2 years ago

@tbsexton thanks for your comment! This might be related to what I'm seeing. However, I find it strange, that yadm seems to continue to work except for that one directory. 😄

ewu63 commented 2 years ago

I found the same issue, and adding for example files under .oh-my-zsh/custom/ did not work either since those files are still under a git repo. My solution was to create a separate directory at $HOME/.oh-my-zsh-custom/, and set $ZSH_CUSTOM to that in the .zshrc file, then commit those to yadm. A bit clumsy and requires manually editing the .zshrc file, but it works.

rtbs-dev commented 2 years ago

I found the same issue, and adding for example files under .oh-my-zsh/custom/ did not work either since those files are still under a git repo. My solution was to create a separate directory at $HOME/.oh-my-zsh-custom/, and set $ZSH_CUSTOM to that in the .zshrc file, then commit those to yadm. A bit clumsy and requires manually editing the .zshrc file, but it works.

Hey this is an elegant solution! I think in my case (possibly others?) the problem arises in the .oh-my-zsh having a .gitignore that specifically calls out /custom. So yadm sees that .gitignore and won't add the content reference (even if there's a valid reference to the plugin submodules in yadm's .gitmodules... nothing gets added to .git/config).

Your solution bypasses the nested repo/.gitignore problem nicely. Now I just need to figure out where I want my $ZSH_CUSTOM to go :sweat_smile:

ewu63 commented 2 years ago

Hey this is an elegant solution! I think in my case (possibly others?) the problem arises in the .oh-my-zsh having a .gitignore that specifically calls out /custom. So yadm sees that .gitignore and won't add the content reference (even if there's a valid reference to the plugin submodules in yadm's .gitmodules... nothing gets added to .git/config).

Your solution bypasses the nested repo/.gitignore problem nicely. Now I just need to figure out where I want my $ZSH_CUSTOM to go 😅

Your explanation makes a lot of sense, I hadn't thought of that specific issue. The documentation on yadm could probably be improved to explain some of this, and in the specific case of oh-my-zsh luckily they already have a mechanism to bypass this. Happy to help!

github-actions[bot] commented 2 years ago

This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been labeled as stale for 7 days with no activity.

terheyden commented 2 years ago

This is still not working, and I suspect it may be a limitation of the git client, and not directly related to yadm.

I wrote a bash script to work around it.

  1. Put this script in your path
  2. cd into the base dir that contains the file you want to add
  3. run the script, so: yadmadd.sh subdir/myfile.txt

For example, I want to yadm add ~/.oh-my-zsh/custom/plugins/install.sh but ~/.oh-my-zsh is its own git dir. I can do this:

cd ~/.oh-my-zsh
yadmadd.sh custom/plugins/install.sh

...and it will work around this bug.

yadmadd.sh

#!/usr/bin/env bash

# A workaround for a bug where yadm won't add files
# already in another git repo (probably a git issue).
#
# https://github.com/TheLocehiliosan/yadm/issues/361
#
# Run this from the base dir with the conflicting .git/ in it.
# Example:
#
#     ~/.oh-my-zsh $ yadmadd.sh custom/plugins/install.sh

# Must be in the root git dir.
if [[ ! -d ".git" ]]; then
    echo
    echo "Run from the conflicted .git repo base dir."
    echo "(I'm looking for a .git/ dir.)"
    echo
    exit 1
fi

tmpdir=/tmp/tmp.git

if [[ -d $tmpdir ]]; then
    echo
    echo "Yo the temp dir already exists. Did I crash?"
    echo "Please reconcile: $tmpdir"
    echo
    exit 1
fi

# Git is just files.
# So just move the .git dir away for a second.
mv .git $tmpdir

# yadm will respect the other repo's .gitignore file
# so be sure to move that too.
tmpignore=/tmp/tmp.gitignore

if [[ -e ".gitignore" ]]; then
    mv .gitignore $tmpignore
fi

# Should work now.
yadm add $1

# Put the .git dir back.
mv $tmpdir .git

# Put the .gitignore back (if it existed).
if [[ -e $tmpignore ]]; then
    mv $tmpignore .gitignore
fi

# Show the yadm status, hopefully with a successfully added file.
yadm status