twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

running single line init script from "get.chezmoi.io" with "--branch" option ignores the "--branch" option #3003

Closed julian-poidevin closed 1 year ago

julian-poidevin commented 1 year ago

Describe the bug

When running the one liner recommended in the docs :

$ sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply $GITHUB_USERNAME

with a --branch option, it seem the --branch option is ignored.

To reproduce

  1. Have a fresh arch-linux install (I'm using a docker container to test)
  2. Run pacman -Sy
  3. Run command to install my dotfiles on the hyprland-tokyo branch : sh -c "$(curl -fsLS git.io/chezmoi)" -- init --branch hyprland-tokyo --apply julian-poidevin
  4. chezmoi seems to be cloning the main branch instead of hyprland-tokyo branch because running git branch -l in /root/.local/share/chezmoi shows "* main"

Expected behavior

The single command sh -c "$(curl -fsLS git.io/chezmoi)" -- init --branch hyprland-tokyo --apply julian-poidevin should run the init on the hyprland-tokyo branch.

Output of command with the --verbose flag

sh -c "$(curl -fsLS git.io/chezmoi)" -- init --verbose --branch=hyprland-tokyo --apply julian-poidevin
info found version 2.33.6 for latest/linux/amd64
info installed ./bin/chezmoi
diff --git a/install-packages.sh b/install-packages.sh
new file mode 100755
index 0000000000000000000000000000000000000000..78feeea4e7bac9dde38c6e2df6522c3bc5dbbf9b
--- /dev/null
+++ b/install-packages.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+
+#Install yay-bin of not available
+if ! command -v yay &> /dev/null
+then
+    sudo pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay-bin && makepkg -si
+fi
+
+SHELL_PACKAGES="\
+    zsh \
+    zsh-thefuck-git \
+    ttf-jetbrains-mono-nerd \
+"
+
+DEV_PACKAGES="\
+    base-devel \
+"
+
+HARDWARE_PACKAGES="\
+    evdi \
+    displaylink \
+"
+
+UTILS_PACKAGES="\
+    docker \
+    docker-compose \
+    docker-buildx \
+    google-chrome \
+    vtop \
+    bmap-tools \
+    can-utils \
+    dropbox \
+    programmer-calculator \
+"
+
+yay -Sy --noconfirm --needed \
+    $SHELL_PACKAGES \
+    $HARDWARE_PACKAGES \
+    $DEV_PACKAGES \
+    $UTILS_PACKAGES
+
+# Add user to the docker group
+sudo usermod $USER --append --group docker
+
warning: git-2.40.1-1 is up to date -- skipping
warning: base-devel-1-1 is up to date -- skipping
 there is nothing to do
Cloning into 'yay'...
remote: Enumerating objects: 468, done.
remote: Counting objects: 100% (468/468), done.
remote: Compressing objects: 100% (312/312), done.
remote: Total 468 (delta 153), reused 453 (delta 153), pack-reused 0
Receiving objects: 100% (468/468), 89.81 KiB | 1.42 MiB/s, done.
Resolving deltas: 100% (153/153), done.
/tmp/3870897070.install-packages.sh: line 7: cd: yay-bin: No such file or directory
/tmp/3870897070.install-packages.sh: line 37: yay: command not found
usermod: group 'docker' does not exist
chezmoi: exit status 6

The script is failing because the install-packages.sh script is bugged on my main branch.

I'm not trying to debug my script here but trying to understand why the branch is not the correct one.

Output of chezmoi doctor

```console [root@5ef5d4ce59e6 ~]# chezmoi doctor RESULT CHECK MESSAGE ok version v2.33.6, commit 5bea2f925fc2b6fcf2ee116a20bae68869746787, built at 2023-05-15T18:52:11Z, built by goreleaser ok latest-version v2.33.6 ok os-arch linux/amd64 (Arch Linux) ok uname Linux 5ef5d4ce59e6 6.1.29-1-lts #1 SMP PREEMPT_DYNAMIC Wed, 17 May 2023 11:35:20 +0000 x86_64 GNU/Linux ok go-version go1.20.4 (gc) ok executable /usr/bin/chezmoi ok upgrade-method upgrade-package ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2023-05-19T03:15:12Z ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set warning edit-command vi not found in $PATH ok edit-args vi ok git-command found /usr/sbin/git, version 2.40.1 warning merge-command vimdiff not found in $PATH ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/sbin/gpg, version 2.2.41 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info dashlane-command dcli not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

N/A

twpayne commented 1 year ago

The script is failing because the install-packages.sh script is bugged on my main branch.

Do you have direct evidence that chezmoi is ignoring the --branch flag, rather than the circumstancial evidence cited?

I tried to reproduce the issue with the following steps:

$ docker pull ubuntu:latest
...
$ docker run -it ubuntu:latest /bin/bash
# apt update && apt install -y curl
...
# sh -c "$(curl -fsLS git.io/chezmoi)" -- init --verbose --branch=hyprland-tokyo --apply julian-poidevin
info found version 2.33.6 for latest/linux/amd64
info installed ./bin/chezmoi
Work email address? work@example.com
Personal email address? user@home.org
...
chezmoi: template: dot_env-secrets.tmpl:8:51: executing "dot_env-secrets.tmpl" at <.bitwarden.github_work_repo_token>: map has no entry for key "bitwarden"
# apt install -y git
...
# chezmoi cd
# git status
On branch hyprland-tokyo
Your branch is up to date with 'origin/hyprland-tokyo'.

nothing to commit, working tree clean

The output of git status indicates that chezmoi has respected the --branch argument to chezmoi init.

Do you have a case which reproduces the problem?

julian-poidevin commented 1 year ago

Sorry I can't manage to reproduce on my side either. Thanks for trying reproducing my issue.