gitbash 1.3.3 → 1.3.5

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.
package/README.md CHANGED
@@ -40,8 +40,17 @@ gitbash reads configuration from `~/.gitbashrc` if it exists. You can set the fo
40
40
  # Prefix for feature branches (default: "feature/")
41
41
  GITBASH_FEATURE_BRANCH_PREFIX="feature/"
42
42
 
43
- # Command for merging (default: "merge")
44
- GITBASH_MERGE_COMMAND="merge"
43
+ # Merge tool command invoked by 'update' when conflicts occur (default: "fork")
44
+ GITBASH_MERGE_COMMAND="fork"
45
+
46
+ # Theme for delta/bat diff highlighting: auto, dark, or light (default: "light")
47
+ GITBASH_THEME="light"
48
+
49
+ # Stale branch threshold in months for 'stale' command (default: 3)
50
+ GITBASH_STALE_MONTHS=3
51
+
52
+ # Cleanup threshold in days - branches merged more than this many days ago (default: 7)
53
+ GITBASH_CLEANUP_DAYS=7
45
54
  ```
46
55
 
47
56
  You can create this file manually or use `gitbash --config` to configure interactively.
@@ -121,13 +130,15 @@ Merge latest main/master into current branch. Opens merge tool on conflicts.
121
130
  ### stale
122
131
 
123
132
  ```bash
124
- stale [-m|--my] [--json] [FILTER...]
133
+ stale [-a|--all] [--age=N] [--json] [FILTER...]
125
134
  ```
126
135
 
127
136
  List remote branches >3 months old (oldest first). Multi-select with TAB to delete.
128
137
 
129
- - `Ctrl-A` toggles showing all branches
130
- - `--my` filters by your git username
138
+ - By default, pre-filters by your git username (from `git config user.name`)
139
+ - `-a|--all` shows all branches without username filter
140
+ - `--age=N` sets stale threshold in months (default: 3, or `GITBASH_STALE_MONTHS`)
141
+ - `Ctrl-A` toggles showing all branches (including recent ones)
131
142
  - `--json` outputs JSON for scripting (same format as cleanup)
132
143
 
133
144
  ### stashes
@@ -126,9 +126,9 @@ EOF
126
126
  # 4. Extract stash IDs safely
127
127
  # -----------------------------
128
128
  local stash_ids=()
129
+ local stash_id line
129
130
  while IFS= read -r line; do
130
- local stash_id
131
- stash_id=$(echo "$line" | grep -o 'stash@{[0-9]\+}')
131
+ stash_id=$(echo "$line" | grep -o 'stash@{[0-9]\+}' || true)
132
132
  if [[ -n "$stash_id" ]]; then
133
133
  stash_ids+=("$stash_id")
134
134
  fi
@@ -157,6 +157,7 @@ EOF
157
157
  echo "Deleting stashes..."
158
158
  # Sort by stash number in descending order to delete safely
159
159
  local sorted_ids=()
160
+ local id
160
161
  while IFS= read -r id; do
161
162
  sorted_ids+=("$id")
162
163
  done < <(printf '%s\n' "${stash_ids[@]}" | sort -t'{' -k2 -rn)
@@ -163,6 +163,10 @@ EOF
163
163
  stale_branches=()
164
164
  recent_branches=()
165
165
 
166
+ # Variables for loop (declared once to avoid zsh output on redeclaration)
167
+ local last_commit_ts relative_date author_email author_name
168
+ local has_remote configured_upstream entry
169
+
166
170
  # Process each local branch
167
171
  while IFS= read -r branch; do
168
172
  # Skip base branch
@@ -170,24 +174,22 @@ EOF
170
174
  [[ -z "$branch" ]] && continue
171
175
 
172
176
  # Get last commit info for all branches
173
- local last_commit_ts relative_date author_email author_name
174
177
  last_commit_ts=$(git log -1 --format='%ct' "$branch" 2>/dev/null)
175
178
  relative_date=$(git log -1 --format='%cr' "$branch" 2>/dev/null)
176
179
  author_email=$(git log -1 --format='%ae' "$branch" 2>/dev/null)
177
180
  author_name=$(git log -1 --format='%an' "$branch" 2>/dev/null)
178
181
 
179
182
  # Check if remote branch exists
180
- local has_remote=false
183
+ has_remote=false
181
184
  if echo "$remote_branches" | grep -qx "$branch"; then
182
185
  has_remote=true
183
186
  fi
184
187
 
185
188
  # Check if it HAD an upstream (was pushed before)
186
- local configured_upstream
187
189
  configured_upstream=$(git config "branch.$branch.remote" 2>/dev/null)
188
190
 
189
191
  # Entry format: timestamp|branch|relative_date|author_email|author_name
190
- local entry="$last_commit_ts|$branch|$relative_date|$author_email|$author_name"
192
+ entry="$last_commit_ts|$branch|$relative_date|$author_email|$author_name"
191
193
 
192
194
  if [[ "$has_remote" == false && -n "$configured_upstream" ]]; then
193
195
  # Had upstream but remote is gone = merged and deleted remotely
@@ -205,9 +207,9 @@ EOF
205
207
  _sort_desc() {
206
208
  local _var="$1"
207
209
  shift
208
- local _out=()
209
- while IFS= read -r line; do
210
- _out+=("$line")
210
+ local _out=() _line
211
+ while IFS= read -r _line; do
212
+ _out+=("$_line")
211
213
  done < <(printf '%s\n' "$@" | sort -t'|' -k1 -rn)
212
214
  # shellcheck disable=SC2034 # assigned via eval to caller var
213
215
  eval "$_var=(\"\${_out[@]}\")"
@@ -427,10 +429,10 @@ Found $total_count branches ($preselect_count pre-selected for deletion)" \
427
429
  local branches_to_delete=()
428
430
  local need_switch=false
429
431
  local only_merged=true
432
+ local branch_name line
430
433
 
431
434
  while IFS= read -r line; do
432
435
  [[ "$line" == "✖ Abort"* ]] && continue
433
- local branch_name
434
436
  branch_name=$(echo "$line" | cut -f2)
435
437
  if [[ -n "$branch_name" ]]; then
436
438
  branches_to_delete+=("$branch_name")
@@ -196,13 +196,13 @@ TYPES
196
196
  print_info "No Jira link provided. Using NOISSUE."
197
197
  else
198
198
  # First try to match just the issue number pattern (e.g., PROJ-123)
199
- issue_number=$(echo "$jira_link" | grep -o -E '^[A-Z]+-[0-9]+$' | head -1)
199
+ issue_number=$(echo "$jira_link" | grep -o -E '^[A-Z]+-[0-9]+$' | head -1 || true)
200
200
 
201
201
  # If not a direct match, try to extract from URL
202
202
  if [[ -z "$issue_number" ]]; then
203
203
  # Match patterns like PROJ-123, ABC-456, etc.
204
204
  # Supports both /browse/PROJ-123 and selectedIssue=PROJ-123 formats
205
- issue_number=$(echo "$jira_link" | grep -o -E '(browse/|selectedIssue=)[A-Z]+-[0-9]+' | grep -o '[A-Z]\+-[0-9]\+' | head -1)
205
+ issue_number=$(echo "$jira_link" | grep -o -E '(browse/|selectedIssue=)[A-Z]+-[0-9]+' | grep -o '[A-Z]\+-[0-9]\+' | head -1 || true)
206
206
  fi
207
207
 
208
208
  if [[ -z "$issue_number" ]]; then
@@ -218,7 +218,6 @@ TYPES
218
218
  echo "Parsed issue number: $issue_number"
219
219
  fi
220
220
  fi
221
- echo
222
221
 
223
222
  # -----------------------------
224
223
  # 3. Get branch title from user (if not already provided)
@@ -242,9 +241,7 @@ TYPES
242
241
  # branch_prefix is set earlier from type menu, flag, or config
243
242
  local branch_name="${branch_prefix}${issue_number}-${branch_title}"
244
243
 
245
- echo
246
244
  echo "Branch name: $branch_name"
247
- echo
248
245
 
249
246
  # -----------------------------
250
247
  # 5. Check if branch already exists
@@ -136,10 +136,13 @@ EOF
136
136
  # -----------------------------
137
137
  # 5. Switch to branch
138
138
  # -----------------------------
139
+ local switch_success=false
139
140
  if [[ "$branch_type" == "local" ]]; then
140
141
  # Switch to local branch
141
142
  echo "Switching to local branch: $branch_name"
142
- git checkout "$branch_name"
143
+ if git checkout "$branch_name"; then
144
+ switch_success=true
145
+ fi
143
146
  else
144
147
  # Handle remote branch
145
148
  local local_branch="${branch_name#*/}" # Remove origin/ prefix
@@ -147,15 +150,52 @@ EOF
147
150
  # Check if local branch already exists
148
151
  if git show-ref --verify --quiet "refs/heads/$local_branch"; then
149
152
  echo "Switching to existing local branch: $local_branch"
150
- git checkout "$local_branch"
153
+ if git checkout "$local_branch"; then
154
+ switch_success=true
155
+ fi
151
156
  else
152
157
  echo "Creating local tracking branch: $local_branch (tracking $branch_name)"
153
- git checkout -b "$local_branch" --track "$branch_name"
158
+ if git checkout -b "$local_branch" --track "$branch_name"; then
159
+ switch_success=true
160
+ fi
154
161
  fi
155
162
  fi
156
163
 
157
- if [[ $? -eq 0 ]]; then
158
- print_success "Successfully switched to branch: $(git rev-parse --abbrev-ref HEAD)"
164
+ if [[ "$switch_success" == true ]]; then
165
+ print_success "Switched to branch: $(git rev-parse --abbrev-ref HEAD)"
166
+
167
+ # -----------------------------
168
+ # 6. Check if branch is behind upstream and offer to pull
169
+ # -----------------------------
170
+ local upstream behind_count
171
+ upstream=$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null || true)
172
+
173
+ if [[ -n "$upstream" ]]; then
174
+ # Fetch to get latest info (silently)
175
+ git fetch origin 2>/dev/null || true
176
+
177
+ # Check how many commits we're behind
178
+ behind_count=$(git rev-list --count HEAD..@{upstream} 2>/dev/null || echo "0")
179
+
180
+ if [[ "$behind_count" -gt 0 ]]; then
181
+ print_warning "Branch is $behind_count commit(s) behind '$upstream'"
182
+ local pull_answer
183
+ prompt_read "Pull latest changes? (Y/n): " pull_answer
184
+ case "$pull_answer" in
185
+ [nN][oO]|[nN])
186
+ print_info "Skipped pulling. Run 'git pull' when ready."
187
+ ;;
188
+ *)
189
+ if git pull; then
190
+ print_success "Successfully pulled latest changes."
191
+ else
192
+ print_error "Pull failed. You may need to resolve conflicts."
193
+ return 1
194
+ fi
195
+ ;;
196
+ esac
197
+ fi
198
+ fi
159
199
  else
160
200
  print_error "Failed to switch branch."
161
201
  return 1
@@ -129,7 +129,7 @@ EOF
129
129
  # 4. Extract stash ID safely
130
130
  # -----------------------------
131
131
  local stash_id
132
- stash_id=$(echo "$selection" | grep -o 'stash@{[0-9]\+}')
132
+ stash_id=$(echo "$selection" | grep -o 'stash@{[0-9]\+}' || true)
133
133
 
134
134
  if [[ -z "$stash_id" ]]; then
135
135
  echo "Error: Could not determine stash ID."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitbash",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Opinionated git utilities for bash with fzf-powered menus",
5
5
  "author": "jaggli",
6
6
  "license": "MIT",