git-branchless icon indicating copy to clipboard operation
git-branchless copied to clipboard

Add a --notes option to 'move' command

Open mfulbright opened this issue 1 year ago • 4 comments

The 'move' command will automatically update all branches in the commits being moved, so that they move with the commits. Which is of course very useful.

It would be great if there was a --notes option that could be passed to the 'move' command that would do the same for commit notes. It would effectively just need to track the original commits and their counterparts after the move, and then run "git notes copy $ORIGINAL_COMMIT $MOVED_COMMIT" for all of them.

mfulbright avatar Jun 19 '24 19:06 mfulbright

Possibly git-branchless should just observe the usual note-rewriting configuration options like https://git-scm.com/docs/git-config#Documentation/git-config.txt-notesrewriteRef

Does note-rewriting work if you enable it and use on-disk rebases (--on-disk)?

arxanas avatar Jun 21 '24 03:06 arxanas

So that's kind of working.

First, here's the config options I set:

$ git config --global --list | grep notes.rewrite notes.rewrite.commit=true notes.rewrite.rebase=true notes.rewriteref=refs/notes/commits

The good news is that setting those options and doing --on-disk moves is copying the notes over! That's great.

The slight bummer is that, as you seem to have expected, if I don't set --on-disk, the notes are not copied when running move.

The bad news is that notes are not copied/maintained when doing a git branchless amend. Even with the notes.rewrite.commit config option set to true.

Watching the output from amend it seems that it's not doing a git commit --amend but instead using git reset to rewrite the commit, so that probably explains why. Though I'm sure you know that and probably know why this isn't working.

reword also isn't copying/maintaining notes. From output, it looks like it's doing an in-memory rebase for its operations. I don't see a --on-disk flag for the reword command.

mfulbright avatar Jun 30 '24 02:06 mfulbright

I didn't test restack, or any other commit-modifying commands other than what's in my commit (if there are any)

mfulbright avatar Jun 30 '24 02:06 mfulbright

Since some of the git-branchless commands just call git rebase, the note-copying logic in git rebase handles it in those cases. For in-memory rebases (including git-branchless amend, which never (?) does an on-disk rebase), there's no opportunity for git rebase to copyt he notes.

I don't know exactly when/how during the rebase Git copies the notes (and what happens, for example, if you rewrite some commits and then abort the rebase?).

The best place to replicate the Git logic would probably be in post_rebase_in_memory:

https://github.com/arxanas/git-branchless/blob/8d99e3d268275446027217a10359b750bbf1b5de/git-branchless-lib/src/core/rewrite/execute.rs#L897-L905

arxanas avatar Jun 30 '24 20:06 arxanas