git-delete-squashed icon indicating copy to clipboard operation
git-delete-squashed copied to clipboard

"[[ not found" using bash

Open smcoll opened this issue 2 years ago • 1 comments
trafficstars

i added this git alias, per docs:

$ git config --global alias.delete-squashed '!f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f' with bin/bash 

But it's failing for some branches, probably since [[ is disabled when run as sh.

git delete-squashed 
Deleted branch my-branch (was d7be4206).
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found

Using Ubuntu 22.04 (bin/bash).

smcoll avatar Mar 10 '23 23:03 smcoll

I took the lazy route of moving the alias body into a separate bash script, and just pointed to said script explicitly within the alias reference, as-per this SO answer.

evenicoulddoit avatar Oct 09 '23 14:10 evenicoulddoit