git-garbage 1.1.10 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/garbage.sh +33 -6
  2. package/package.json +1 -1
package/garbage.sh CHANGED
@@ -5,7 +5,7 @@ if test -n "$(git status --porcelain)"; then
5
5
  exit 1;
6
6
  fi
7
7
 
8
- if ! git fetch --quiet 2> /dev/null; then
8
+ if ! git fetch --prune --quiet 2> /dev/null; then
9
9
  echo 'There was a problem fetching your branch.' >&2;
10
10
  exit 1;
11
11
  fi
@@ -15,15 +15,42 @@ current="$(git rev-parse --abbrev-ref HEAD)"
15
15
  declare -a branches
16
16
 
17
17
  # merged
18
- for branch in $(git for-each-ref --format "%(refname:short)" refs/heads/ --merged | grep -E -v "$current"); do
19
- branches+=("$branch")
18
+ for branch in $(git for-each-ref --format "%(refname:short)" refs/heads/ --merged); do
19
+ if [[ "$branch" != "$current" ]]; then
20
+ branches+=("$branch")
21
+ fi
20
22
  done
21
23
 
22
24
  # squashed
23
25
  for branch in $(git for-each-ref --format "%(refname:short)" refs/heads/); do
24
- mergeBase=$(git merge-base "$current" "$branch")
25
- if [[ $(git cherry "$current" "$(git commit-tree "$(git rev-parse "$branch^{tree}")" -p "$mergeBase" -m _)") == "-"* ]]; then
26
- branches+=("$branch")
26
+ if [[ "$branch" != "$current" ]]; then
27
+ mergeBase=$(git merge-base "$current" "$branch")
28
+ if [[ $(git cherry "$current" "$(git commit-tree "$(git rev-parse "$branch^{tree}")" -p "$mergeBase" -m _)") == "-"* ]]; then
29
+ branches+=("$branch")
30
+ fi
31
+ fi
32
+ done
33
+
34
+ # branches that were part of PR workflow (feature branches with remote deleted)
35
+ for branch in $(git for-each-ref --format "%(refname:short)" refs/heads/); do
36
+ if [[ "$branch" != "$current" ]]; then
37
+ # Check if branch has commits not in main (indicating it was a feature branch)
38
+ if [[ $(git rev-list --count "$current..$branch" 2>/dev/null) -gt 0 ]]; then
39
+ # Check if remote branch doesn't exist (indicating PR was closed and branch deleted)
40
+ if ! git show-ref --verify --quiet "refs/remotes/origin/$branch"; then
41
+ # Check if branch is already in our list to avoid duplicates
42
+ branch_exists=false
43
+ for existing_branch in "${branches[@]}"; do
44
+ if [[ "$existing_branch" == "$branch" ]]; then
45
+ branch_exists=true
46
+ break
47
+ fi
48
+ done
49
+ if [[ "$branch_exists" == false ]]; then
50
+ branches+=("$branch")
51
+ fi
52
+ fi
53
+ fi
27
54
  fi
28
55
  done
29
56
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "git-garbage",
3
3
  "description": "Delete local git branches after deleting them on the remote repository.",
4
4
  "homepage": "https://github.com/Kikobeats/git-garbage",
5
- "version": "1.1.10",
5
+ "version": "1.1.12",
6
6
  "bin": {
7
7
  "git-garbage": "garbage.sh"
8
8
  },