git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Automatically re-running commands during an interactive rebase or post commit

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
May 29, 2023, 17:53 UTC
Message-ID
<198eea19-fc40-de0c-8854-3cdc94925f32@gmail.com>
In-Reply-To
<CACoUkn6F_=JR5SYBWL2sVDxDVAZbxcV5Ruif6wLba-_q_QNiZg@mail.gmail.com>
Hi Paul
On 29/05/2023 17:02, Paul Jolly wrote:
Show 12 quoted lines
>> I would appreciate some advice on the best way to solve the following problem.
> 
> Replying to self with some updates based on further investigations.
> 
> The lack of pre-commit like hook during a rebase is documented in a
> few places (https://adamj.eu/tech/2022/11/07/pre-commit-run-hooks-rebase/
> to list one). The -x flag provides a means by which I can
> retrospectively amend the "previous" commit if that is not clean. Not
> ideal, but a solution of sorts.
> 
> However, the main problem appears to be the lack of "hook" to do
> something when git rebase detects conflicts.

I think you could get around this by using a script that wraps "git rebase". Something like

while true
do
     if test -d "$(git rev-parse --git-path rebase-merge)"
     then
	git rebase --continue
     else
	git rebase "$@"
     fi
     if test $? -eq 0
     then
	exit 0
     fi
     # Handle conflicts here
     if automatic-conflict-resolution-failed
     then
         exit 1
     fi
done
You can get a list of the files that have conflicts with
	git diff-index --name-only --diff-filter=U HEAD --
or by parsing the output of
	git status --porcelain

I did wonder if you could use a custom merge driver (see man gitattributes) for the file with the checksums but that would be run before all the other files have been merged. Another alternative might be to use a custom merge strategy that runs "git merge-ort" and then cleans up the conflicts in the checksum file. You can specify a custom strategy by naming your script "git-merge-foo" and passing "-s foo" to git rebase.

Best Wishes
Phillip
Show 10 quoted lines
> Ideally, I would like to have a hook be called when git rebase detects
> a conflict, a hook in which I could attempt to "recover" the
> situation. If that hook failed to fully recover the situation, git
> rebase would fail as it currently does. Otherwise, it would be able to
> continue as normal.
> 
> My use of git is pretty basic, so part of me feels like I can't be the
> first person to run into this problem!
> 
> As ever, any pointers are greatly appreciated.
Previous: Paul JollyNext: Paul Jolly
Message 5 of 13 in “Automatically re-running commands during an interactive rebase or post commit”
  1. Paul JollyMay 29, 2023
  2. rsbecker@nexbridge.comMay 29, 2023
  3. Paul JollyMay 29, 2023
  4. Paul JollyMay 29, 2023
  5. Phillip WoodMay 29, 2023
  6. Paul JollyMay 29, 2023
  7. Phillip WoodMay 29, 2023
  8. Elijah NewrenMay 31, 2023
  9. Phillip WoodJun 2, 2023
  10. Paul JollyJun 8, 2023
  11. Son Luong NgocMay 30, 2023
  12. Oswald BuddenhagenMay 30, 2023
  13. Paul JollyMay 30, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.