Skip to content

Commit

Permalink
Merge pull request #8 from davidraviv/remove_node_dependancy
Browse files Browse the repository at this point in the history
Remove dependency on Node.js
  • Loading branch information
davidraviv authored Sep 19, 2021
2 parents 4c64276 + a3c2458 commit 41c7393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ Use the `--dry-run` flag to see the list of branches to be deleted before actual

When using the `--dry-run` flag, deleting the branches is skipped. All the rest is always performed.
## Dependencies
The extension relays on:
- gh CLI v2.0
- git v2.22
The extension depends on:
- zsh
- node.js

I may remove the last two dependencies, they are not really needed (pull requests are welcomed!). It helped me for fast developing it.
- git v2.22
- gh CLI v2.0
22 changes: 9 additions & 13 deletions gh-clean-branches
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,20 @@ remote_branches_str=${remote_branches_str//${upstream_name}\// } # trim the "ori
printf "%s\n%s\n" "${blue}Local branches:${end}" "${local_branches_str}"
printf "%s\n%s\n" "${blue}Remote branches:${end}" "${remote_branches_str}"

missing_upstream_branches_str=`node -e "
const args = process.argv.slice(1);
const local_branches_str = args[0]
const remote_branches_str = args[1]
setopt extended_glob
local_branches=("${(f)local_branches_str}") # split string by \n to array
local_branches=(${local_branches:#* ${default_branch}}) # filter out default_branch
local_branches=(${local_branches// ##}) # trim spaces

local_branches = local_branches_str.trim().split('\n').filter(b => !b.includes(' ${default_branch}')).map(b => b.trim())
remote_branches = remote_branches_str.trim().split('\n').filter(b => !b.includes(' ${default_branch}')).map(b => b.trim())
missing_upstream_branches = local_branches.filter(b => !remote_branches.includes(b))
remote_branches=("${(f)remote_branches_str}") # split string by \n to array
remote_branches=(${remote_branches:#* ${default_branch}}) # filter out default_branch
remote_branches=(${remote_branches// ##}) # trim spaces

console.log(missing_upstream_branches.join(','))
" $local_branches_str $remote_branches_str`

missing_upstream_branches=("${(@s/,/)missing_upstream_branches_str}") # @ modifier
missing_upstream_branches=(${local_branches:|remote_branches}) # local_branches minus remote_branches

branches_count=${#missing_upstream_branches[@]}

# No results returns an array with a single empty element
if [[ ${branches_count} -eq 1 ]] && [[ -z "${missing_upstream_branches[1]}" ]]; then
if [[ ${branches_count} -eq 0 ]]; then
printf "%s\n" "${green}No local branches with missing upstream found${end}"
else
printf "%s\n" "${blue}Local branches with missing upstream:${end}"
Expand Down

0 comments on commit 41c7393

Please sign in to comment.