stacked-git / stgit

Stacked Git
https://stacked-git.github.io/
GNU General Public License v2.0
535 stars 61 forks source link

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

Open fbenkstein opened 3 months ago

fbenkstein commented 3 months ago

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.

jpgrayson commented 3 months ago

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.

fbenkstein commented 3 months ago

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?

jpgrayson commented 3 months ago

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