TheLocehiliosan / yadm

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

Template does not process if multiple classes exist #437

Open kovalchik opened 1 year ago

kovalchik commented 1 year ago

Describe the bug

If multiple local classes are specified, templates do not seem to process or produce a file.

To reproduce

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

Steps to reproduce the behavior:

  1. Run command yadm init
  2. Run command yadm config local.class someclass
  3. Run command echo "This is a sample text" > example.txt##template
  4. Run command yadm add example.txt##template
  5. Run command yadm status
  6. Run command ls
  7. Run command rm example
  8. Run command yadm config --add local.class someotherclass
  9. Run command yadm status
  10. Run command ls

Expected behavior

The file example.txt should be created each time yadm status is run. However, the example.txt file is not created after adding the second class. The following output is seen after yadm commands, if there are two local classes:

awk: newline in string someclass
someotherclass... at source line 1

Environment

Additional context

I was unable to reproduce this with the yadm docker image. I was unable to product any files via alternative or template files with the docker image. I assume that problem is either user error or unrelated to this issue.

TheLocehiliosan commented 1 year ago

I've not been able to recreate this problem. I specifically was using version 3.2.1 and Git version 2.38.0, but on Linux. It might be some issue with the version of awk being use (based on output you mentioned)? Can let me know the output of awk --version, and if possible, could you try again using gawk/awk brew installed?

Can you doublecheck your instructions to reproduce? For example, where you write rm example, I think you probably meant rm example.txt.

Can you also show me the output of:

yadm alt

and the output of:

yadm config --get-all local.class

kovalchik commented 1 year ago

Installing awk through Homebrew did not resolve the issue. However, installing gawk via Homebrew did fix the issue! 🙌

Here's the outputs you asked for, in case you're still interested in trying to replicate this.

MacOS 12.6 awk version: 20200816 Homebrew awk version: 20211208 GNU Awk (gawk) version: 5.2.0

This is the output of yadm alt using the MacOS built in awk (class names have been changed to classone and classtwo for clarity):

Linking /Users/darrenk/.config/fish/functions/project_specific_functions.fish##class.classtwo to /Users/darrenk/.config/fish/functions/project_specific_functions.fish
Linking /Users/darrenk/.config/git/config.local##class.classone to /Users/darrenk/.config/git/config.local
Linking /Users/darrenk/.config/git/config.classtwo##class.classtwo to /Users/darrenk/.config/git/config.classtwo
Creating /Users/darrenk/Brewfile from template /Users/darrenk/Brewfile##template
awk: newline in string classone
classtwo... at source line 1

This is the output of yadm config --get-all local.class using the MacOS build in awk:

classone
classtwo
awk: newline in string classone
classtwo... at source line 1
rasa commented 1 year ago

Should https://github.com/TheLocehiliosan/yadm/blob/abf6ea4b610f50f6bf6ff51fc351ffb6bd7c70e1/yadm#L1780-L1785 read:

function set_awk() {
  local pgm
  for pgm in "${AWK_PROGRAM[@]}"; do
    command -v "$pgm" &> /dev/null && AWK_PROGRAM=("$pgm") && return
    [[ "$OSTYPE" =~ ^[Dd]arwin ]] && return # only gawk works on MacOS
  done
}

?

TheLocehiliosan commented 1 year ago

Should

I'm not sure. Perhaps the internal template processor can be made compatible with the MacOS awk.