stgit icon indicating copy to clipboard operation
stgit copied to clipboard

[feature request]: run command on each (applied) patch

Open fbenkstein opened this issue 1 year ago • 3 comments

Hi,

I switched from a git rebase --interactive based workflow to stgit and it's working great. One thing I'm missing occasionally is git rebase --exec '...' which allows me to run a command on each patch, e.g. to check if build and tests are still working after reshuffling patches or rebasing.

I came up with an alias which provides a crude immitation of the feature but having something built-in would be quite useful:

[stgit "alias"]
  foreach = "!bash -c 'for ((i=0, n=$(stg series -cA); i < n; i++)); do stg goto $i || break; ( set -xe; \"$@\" ) || { ret=$?; echo "Exit code $ret" >&2; exit $ret; }; done'" --

I'd be willing to try implementing this myself if such a patch has a chance of being accepted.

Thank you, Frank.

fbenkstein avatar Jul 10 '24 10:07 fbenkstein

I'm not categorically opposed to StGit having this kind of feature. But I do want to be careful about only adding features that are generally useful and have a good risk-to-value proposition.

Would you want a stg foreach command that behaves as your alias does?

Or are you imagining some StGit commands gaining a --exec option?

What's the scope?

I'll also note that if we implemented #241, then it would be possible to write a stg-foreach script that lived in $PATH that could be run as stg foreach. It would be an easy call to add such a script to the contrib directory.

jpgrayson avatar Jul 10 '24 13:07 jpgrayson

How about stg rebase --exec '...' having the same semantics as git rebase --exec '...', see https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---execltcmdgt?

fbenkstein avatar Jul 10 '24 13:07 fbenkstein

If that covers your use cases, it make sense to me to do it that way.

jpgrayson avatar Jul 10 '24 16:07 jpgrayson