-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix prompt dialog and setup issues (#15)
* Fix prompt dialog and setup issues * Improve git default_branch script to check the local config * Add more detailed comment
- Loading branch information
Showing
15 changed files
with
71 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 29 additions & 12 deletions
41
home/private_dot_config/private_fish/functions/__git.default_branch.fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
# Reference: | ||
# https://github.com/jhillyerd/plugin-git/blob/master/functions/__git.default_branch.fish | ||
function __git.default_branch | ||
# Attempt to get the global default branch name from Git configuration | ||
set -l git_default_branch (git config --get init.defaultBranch) | ||
if test -z "$git_default_branch" | ||
# If not configured, default to 'main' | ||
set git_default_branch "main" | ||
end | ||
|
||
# Get the remote name, defaulting to 'origin' | ||
set -l remote (git remote show | head -n 1) | ||
if test -z "$remote" | ||
# If no remote is found, use the configured default branch or 'main' | ||
echo "No remote found, defaulting to '$git_default_branch'" | ||
echo $git_default_branch | ||
return | ||
end | ||
|
||
# Fetch remote information to ensure we have the latest default branch info, | ||
# cleaning up any references that doesn't exist anymore. | ||
git remote update $remote --prune | ||
|
||
# Extract the default branch name from the 'HEAD branch' line of the 'git remote show' output | ||
set -l default_branch (git remote show $remote | grep 'HEAD branch' | sed 's/.*: //') | ||
if test -z "$default_branch" | ||
echo "Could not determine the default branch from remote, defaulting to '$git_default_branch'" | ||
echo $git_default_branch | ||
return | ||
end | ||
|
||
function __git.default_branch -d "Use init.defaultBranch if it's set and exists, otherwise use main if it exists. Falls back to master" | ||
command git rev-parse --git-dir &>/dev/null; or return | ||
if set -l default_branch (command git config --get init.defaultBranch) | ||
and command git show-ref -q --verify refs/heads/{$default_branch} | ||
echo $default_branch | ||
else if command git show-ref -q --verify refs/heads/main | ||
echo main | ||
else | ||
echo master | ||
end | ||
end | ||
end |