Skip to content

Commit 0074697

Browse files
authored
Use a separate .git/SCM_BREEZE_COMMIT_MSG file for each repo (#356)
When I'm working on multiple projects, it's annoying when the saved git commit message is global and not unique to each repo.`/tmp/.git_commit_message~` was a bad idea! I also use the `grsl` alias quite a lot (which means "git reset last commit"). I realized it would be really handy to store that commit message in `.git/SCM_BREEZE_COMMIT_MSG` as well so that I can reset to the previous commit, make a change, then hit Ctrl+X+space to commit again with the same message.
2 parents b2e9e6a + 9a19e2b commit 0074697

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/git/aliases.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ _alias "$exec_scmb_expand_args_alias" 'exec_scmb_expand_args'
9494
_alias "$git_show_files_alias" 'git_show_affected_files'
9595
_alias "$git_commit_all_alias" 'git_commit_all'
9696
_alias "$git_grep_shortcuts_alias" 'git_grep_shortcuts'
97+
_alias "$git_reset_last_commit" 'git_reset_last_commit'
9798

9899
# Git Index alias
99100
_alias "$git_index_alias" 'git_index'
@@ -145,7 +146,6 @@ if [ "$GIT_SETUP_ALIASES" = "yes" ]; then
145146
__git_alias "$git_rebase_interactive_alias" 'git' 'rebase' '-i'
146147
__git_alias "$git_rebase_alias_continue" 'git' 'rebase' '--continue'
147148
__git_alias "$git_rebase_alias_abort" 'git' 'rebase' '--abort'
148-
__git_alias "$git_reset_last_commit" 'git' 'reset HEAD~'
149149
__git_alias "$git_top_level_alias" 'git' 'rev-parse' '--show-toplevel'
150150
__git_alias "$git_merge_alias" 'git' 'merge'
151151
__git_alias "$git_merge_no_fast_forward_alias" 'git' 'merge' '--no-ff'

lib/git/status_shortcuts.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
217217
git_commit_prompt() (
218218
local commit_msg
219219
local saved_commit_msg
220-
if [ -f "/tmp/.git_commit_message~" ]; then
221-
saved_commit_msg="$(cat /tmp/.git_commit_message~)"
220+
# Use repo-specific commit message file in .git/ directory (follows git's naming convention)
221+
local git_dir
222+
git_dir="$(git rev-parse --git-dir 2>/dev/null)"
223+
local commit_msg_file="${git_dir}/SCM_BREEZE_COMMIT_MSG"
224+
if [ -f "$commit_msg_file" ]; then
225+
saved_commit_msg="$(cat "$commit_msg_file")"
222226
echo -e "\033[0;36mLeave blank to use saved commit message: \033[0m$saved_commit_msg"
223227
fi
224228
if breeze_shell_is "zsh"; then
@@ -257,7 +261,7 @@ git_commit_prompt() (
257261
fi
258262

259263
# Also save the commit message to a temp file in case git commit fails
260-
echo "$commit_msg" >"/tmp/.git_commit_message~"
264+
echo "$commit_msg" > "$commit_msg_file"
261265
eval $@ # run any prequisite commands
262266

263267
echo "$commit_msg" | git commit -F - | tail -n +2
@@ -271,7 +275,7 @@ git_commit_prompt() (
271275
fi
272276
if [[ "$git_exit_status" == 0 ]]; then
273277
# Delete saved commit message if commit was successful
274-
rm -f "/tmp/.git_commit_message~"
278+
rm -f "$commit_msg_file"
275279
fi
276280
)
277281

@@ -302,3 +306,15 @@ git_add_and_commit() (
302306
echo "# No staged changes to commit."
303307
fi
304308
)
309+
310+
# Reset last commit and save its message for reuse
311+
git_reset_last_commit() {
312+
fail_if_not_git_repo || return 1
313+
local git_dir
314+
git_dir="$(git rev-parse --git-dir 2>/dev/null)"
315+
if [ -n "$git_dir" ]; then
316+
# Save the current commit message before resetting
317+
git log -1 --pretty=%B > "$git_dir/SCM_BREEZE_COMMIT_MSG"
318+
fi
319+
git reset HEAD~ "$@"
320+
}

0 commit comments

Comments
 (0)