1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2025-12-12 15:34:50 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Matthew Boston
971fa9a052
Merge bfb0e05ffa into 92aed2e936 2025-12-10 14:09:14 +04:00
Tanzim Hossain Romel
92aed2e936
feat(extract): add unar as fallback for RAR extraction (#13472)
Add unar as a fallback when unrar is not available for extracting
RAR files. This addresses the issue where unrar has been removed
from Homebrew due to licensing issues.

The extraction now:
- Prefers unrar if available (backward compatible)
- Falls back to unar if unrar is not found
- Shows helpful error message if neither tool is installed
2025-12-09 20:14:31 +01:00
Matthew Boston
bfb0e05ffa
fix(git-prompt): improve branch name resolution using symbolic-ref
Problem:
In worktrees, enabling reftable caused the gitfast prompt to sometimes show “.invalid” for the branch name, e.g. `git:(.invalid|SPARSE)`. The cause was gitfast’s __git_ps1 reading $GIT_DIR/HEAD (and sequencer head-name files) directly and attempting to derive the ref name by string slicing. That approach is brittle with worktrees and newer ref backends like reftable.

What changed:
- Prefer `git symbolic-ref --short HEAD` to resolve the branch name.
- Also use `--short` when HEAD is a symlink.
- Keep existing fallbacks (describe/detached SHA) unchanged.

Why this is correct:
- Delegates ref resolution to Git’s ref API, which understands:
  - multiple worktrees (`.git/worktrees/<name>/HEAD`)
  - all ref storage backends (loose, packed, reftable)
  - edge cases around in-progress operations and symlinks
- Avoids parsing internal files that can legitimately be non-canonical or transient (e.g., head-name during rebase, or placeholders that appear as “.invalid” with reftable+worktrees).

Impact:
- Correct branch names in worktrees regardless of ref backend (fixes “.invalid”).
- Detached HEAD behavior remains: still falls back to describe/short SHA.
- `|SPARSE` logic unchanged and still driven by `core.sparseCheckout`.
- Backwards-compatible: older Git that supports `symbolic-ref --short` works; fallbacks still apply if not a branch.

Rationale:
Ref backends like reftable decouple refs from the filesystem layout that gitfast was implicitly depending on. Using Git’s plumbing for branch resolution is the robust, future-proof approach.
2025-10-31 12:19:24 -06:00
2 changed files with 13 additions and 2 deletions

View File

@ -77,7 +77,15 @@ EOF
(*.lzma) unlzma "$full_path" ;; (*.lzma) unlzma "$full_path" ;;
(*.z) uncompress "$full_path" ;; (*.z) uncompress "$full_path" ;;
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;; (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;;
(*.rar) unrar x -ad "$full_path" ;; (*.rar)
if (( $+commands[unrar] )); then
unrar x -ad "$full_path"
elif (( $+commands[unar] )); then
unar -o . "$full_path"
else
echo "extract: cannot extract RAR files: install unrar or unar" >&2
success=1
fi ;;
(*.rpm) (*.rpm)
rpm2cpio "$full_path" | cpio --quiet -id ;; rpm2cpio "$full_path" | cpio --quiet -id ;;
(*.7z | *.7z.[0-9]* | *.pk7) 7za x "$full_path" ;; (*.7z | *.7z.[0-9]* | *.pk7) 7za x "$full_path" ;;

View File

@ -474,9 +474,12 @@ __git_ps1 ()
if [ -n "$b" ]; then if [ -n "$b" ]; then
: :
# Prefer symbolic-ref short name resolution (works well with worktrees)
elif symref_short="$(git symbolic-ref --quiet --short HEAD 2>/dev/null)" && [ -n "$symref_short" ]; then
b="$symref_short"
elif [ -h "$g/HEAD" ]; then elif [ -h "$g/HEAD" ]; then
# symlink symbolic ref # symlink symbolic ref
b="$(git symbolic-ref HEAD 2>/dev/null)" b="$(git symbolic-ref --short HEAD 2>/dev/null)"
else else
local head="" local head=""
if ! __git_eread "$g/HEAD" head; then if ! __git_eread "$g/HEAD" head; then