Merge branch 'master' of github.com:scmbreeze/scm_breeze

* 'master' of github.com:scmbreeze/scm_breeze:
  fix rc file suffix in README
  Return error code from git branch command.
  Use File.exist over deprecated File.exists
  Speed up and simplify parse_git_branch
  Define git functions with parentheses instead of curly braces, so that we can press Ctrl+C to quit the commit prompt without terminating the shell session. (Parentheses run the function in a subshell.)
This commit is contained in:
Jeff Byrnes
2023-07-16 16:00:07 -04:00
6 changed files with 10 additions and 10 deletions

View File

@@ -181,7 +181,7 @@ doesn't need to 'learn' anything, and it can do SCM-specific stuff like:
The default alias for `git_index` is 'c', which might stand for 'code' The default alias for `git_index` is 'c', which might stand for 'code'
You will first need to configure your repository directory by setting `GIT_REPO_DIR` in `~/.git.sbmrc`. You will first need to configure your repository directory by setting `GIT_REPO_DIR` in `~/.git.scmbrc`.
Then, build the index: Then, build the index:

View File

@@ -17,7 +17,7 @@ function _scmb_git_branch_shortcuts {
# Fall back to normal git branch, if any unknown args given # Fall back to normal git branch, if any unknown args given
if [[ "$($_git_cmd branch | wc -l)" -gt 300 ]] || ([[ -n "$@" ]] && [[ "$@" != "-a" ]]); then if [[ "$($_git_cmd branch | wc -l)" -gt 300 ]] || ([[ -n "$@" ]] && [[ "$@" != "-a" ]]); then
exec_scmb_expand_args $_git_cmd branch "$@" exec_scmb_expand_args $_git_cmd branch "$@"
return 1 return $?
fi fi
# Use ruby to inject numbers into git branch output # Use ruby to inject numbers into git branch output

View File

@@ -171,7 +171,7 @@ function is_git_dirty {
[[ $($GIT_BINARY status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" [[ $($GIT_BINARY status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
} }
function parse_git_branch { function parse_git_branch {
$GIT_BINARY branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/" git rev-parse --abbrev-ref HEAD 2> /dev/null
} }
# If the working directory is clean, update the git repository. Otherwise, show changes. # If the working directory is clean, update the git repository. Otherwise, show changes.

View File

@@ -88,7 +88,7 @@ puts "%s#%s On branch: %s#{@branch}#{difference}%s %s| [%s*%s]%s => $#{ENV["gi
] ]
def has_modules? def has_modules?
@has_modules ||= File.exists?(File.join(@project_root, '.gitmodules')) @has_modules ||= File.exist?(File.join(@project_root, '.gitmodules'))
end end
# Index modification states # Index modification states

View File

@@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
# * Execute prerequisite commands if message given, abort if not # * Execute prerequisite commands if message given, abort if not
# * Pipe commit message to 'git commit' # * Pipe commit message to 'git commit'
# * Add escaped commit command and unescaped message to bash history. # * Add escaped commit command and unescaped message to bash history.
git_commit_prompt() { git_commit_prompt() (
local commit_msg local commit_msg
local saved_commit_msg local saved_commit_msg
if [ -f "/tmp/.git_commit_message~" ]; then if [ -f "/tmp/.git_commit_message~" ]; then
@@ -268,10 +268,10 @@ git_commit_prompt() {
# Delete saved commit message if commit was successful # Delete saved commit message if commit was successful
rm -f "/tmp/.git_commit_message~" rm -f "/tmp/.git_commit_message~"
fi fi
} )
# Prompt for commit message, then commit all modified and untracked files. # Prompt for commit message, then commit all modified and untracked files.
git_commit_all() { git_commit_all() (
fail_if_not_git_repo || return 1 fail_if_not_git_repo || return 1
changes=$(git status --porcelain | wc -l | tr -d ' ') changes=$(git status --porcelain | wc -l | tr -d ' ')
if [ "$changes" -gt 0 ]; then if [ "$changes" -gt 0 ]; then
@@ -283,10 +283,10 @@ git_commit_all() {
else else
echo "# No changed files to commit." echo "# No changed files to commit."
fi fi
} )
# Add paths or expanded args if any given, then commit all staged changes. # Add paths or expanded args if any given, then commit all staged changes.
git_add_and_commit() { git_add_and_commit() (
fail_if_not_git_repo || return 1 fail_if_not_git_repo || return 1
git_silent_add_shortcuts "$@" git_silent_add_shortcuts "$@"
changes=$(git diff --cached --numstat | wc -l) changes=$(git diff --cached --numstat | wc -l)
@@ -296,4 +296,4 @@ git_add_and_commit() {
else else
echo "# No staged changes to commit." echo "# No staged changes to commit."
fi fi
} )

0
test.sh Normal file
View File