Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running git funcitons in subshell breaks vared in zsh #321

Open
AndreasArledal opened this issue Nov 17, 2022 · 9 comments
Open

Running git funcitons in subshell breaks vared in zsh #321

AndreasArledal opened this issue Nov 17, 2022 · 9 comments

Comments

@AndreasArledal
Copy link

136fb6b breaks git_command_prompt in my zsh setup. Seems like vared is not working properly in subshell.

git_commit_prompt:vared:8: ZLE not enabled

@saiqulhaq-hh
Copy link

saiqulhaq-hh commented Dec 5, 2022

so I have to downgrade?
it's not working on my WSL terminal

@saiqulhaq-hh
Copy link

image
it works after I checkout the previous commit
thanks

@M-Porter
Copy link

M-Porter commented Dec 5, 2022

Confirmed rolling back to previous commit of 6c85b86 fixes the issue.

Commit message of 136fb6b states

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.)

I do not have the issue. I am able to ctrl-c without my current shell session terminating.

Can we get a rollback then a PR with the proposed changes as not to break environments by just pushing to main.

@mattflo-outpace
Copy link

Took me a while to find this. I reverted the offending commit locally. This should get fixed. Super annoying.

@ghthor
Copy link
Member

ghthor commented Dec 29, 2022

I think this is the reason[1] this isn't working after the targeted commit. When these were changed to running in a subshell, the vared aka variable edit command that is provided by zsh is not longer available, as the function in now running in a subshell that is non-interactive??

The reason for running these functions in a subshell seems legitimate, so I not sure how to handle the situation? Maybe removing the usage of vared here? Maybe reverting 136fb6b and only running the parts of the functions that block/wait/take a long time within a subshell so that ctrl+c doesn't exit the interactive shell that called the function?

Sorry for the annoyance

[1] 136fb6b#diff-9070c9d1a356a6ef9eacfc3002d78d0d9b5b88ba9c8509884d66564f3a7aa3ccR220

@Tobbe
Copy link
Contributor

Tobbe commented Oct 9, 2023

I just ran into this too. So leaving a comment to bump this issue 🙂

@saiqulhaq
Copy link

cd ~/.scm_breeze
git checkout 6c85b86

@isDipesh
Copy link

Undoing the diff only for lib/git/status_shortcuts.sh as linked by @ghthor worked for me without having to checkout to some other commit for the whole repo.

cd ~/.scm_breeze
git checkout 136fb6b4ee446fff8bd976768702200460714c96~1 -- lib/git/status_shortcuts.sh

@edelgado
Copy link

Thanks @isDipesh! Yeah apparently it's the use of parenthesis instead of brackets in these functions ¯_(ツ)_/¯

diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh
index 54b3191..a8616ce 100644
--- a/lib/git/status_shortcuts.sh
+++ b/lib/git/status_shortcuts.sh
@@ -209,7 +209,7 @@ theirs(){ _git_resolve_merge_conflict "their" "$@"; }
 # * Execute prerequisite commands if message given, abort if not
 # * Pipe commit message to 'git commit'
 # * Add escaped commit command and unescaped message to bash history.
-git_commit_prompt() {
+git_commit_prompt() (
   local commit_msg
   local saved_commit_msg
   if [ -f "/tmp/.git_commit_message~" ]; then
@@ -268,10 +268,10 @@ git_commit_prompt() {
     # Delete saved commit message if commit was successful
     rm -f "/tmp/.git_commit_message~"
   fi
-}
+)

 # Prompt for commit message, then commit all modified and untracked files.
-git_commit_all() {
+git_commit_all() (
   fail_if_not_git_repo || return 1
   changes=$(git status --porcelain | wc -l | tr -d ' ')
   if [ "$changes" -gt 0 ]; then
@@ -283,10 +283,10 @@ git_commit_all() {
   else
     echo "# No changed files to commit."
   fi
-}
+)

 # 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
   git_silent_add_shortcuts "$@"
   changes=$(git diff --cached --numstat | wc -l)
@@ -296,4 +296,4 @@ git_add_and_commit() {
   else
     echo "# No staged changes to commit."
   fi
-}
+)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants