JanDeDobbeleer / aliae

Cross shell and platform alias management
https://aliae.dev
MIT License
73 stars 3 forks source link

Git repo is checked before when git aliases are used #86

Closed trajano closed 5 months ago

trajano commented 5 months ago

Code of Conduct

What happened?

Seems like it is checking for a git repo when git aliases are used.

+++++ git rev-parse --abbrev-ref HEAD
fatal: not a git repository (or any of the parent directories): .git

What OS are you seeing the problem on?

Linux

Which shell are you using?

bash

JanDeDobbeleer commented 5 months ago

@trajano what's the config like?

trajano commented 5 months ago
alias:
  - name: ac
    value: "!git add -A && git commit"
    type: git

  - name: fp
    value: fetch --prune
    type: git

  - name: puf
    value: "!git push --force --set-upstream origin $(git rev-parse --abbrev-ref HEAD)"
    type: git

  - name: lg
    value: log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    type: git

  - name: r
    value: "!git fp && (GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash origin/HEAD || GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash origin/master)"
    type: git

  - name: dh
    value: diff --name-status origin/HEAD
    type: git

This is partial the full aliae config is pretty long

trajano commented 5 months ago

I think it's this one

value: "!git push --force --set-upstream origin $(git rev-parse --abbrev-ref HEAD)"

Somehow it's executing the value inside

It generates this

git config --global alias.puf "!git push --force --set-upstream origin $(git rev-parse --abbrev-ref HEAD)"

But ideally it should be (note single quotes)

git config --global alias.puf '!git push --force --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'

Work around to use back ticks didn't work

value: "!git push --force --set-upstream origin `git rev-parse --abbrev-ref HEAD`"
trajano commented 5 months ago

This one worked

  - name: puf
    value: "!git push --force --set-upstream origin \\$(git rev-parse --abbrev-ref HEAD)"
    type: git

which generates

git config --global alias.puf "!git push --force --set-upstream origin \$(git rev-parse --abbrev-ref HEAD)"