jj icon indicating copy to clipboard operation
jj copied to clipboard

FR: Jujutsu should be able to apply patches to files in a repo.

Open PhilipMetzger opened this issue 2 years ago • 15 comments

As Windows ships no patch utility by default, it would be nice to have something like it built into Jujutsu.

PhilipMetzger avatar Dec 14 '23 18:12 PhilipMetzger

My idea for a basic outline of the command is:

  • jj patch apply equivalent to git am
  • jj patch series for integrating with the patch-series container format (cc @emilazy)

Multiple concerns were raised because jj patch seems to imply patch(1) behavior for multiple, I do not agree with it though.

Yuya also brought up -T email in another issue, which also may work for some use-cases, but that needs in my opinion some further discussion.

PhilipMetzger avatar Dec 29 '24 22:12 PhilipMetzger

Alternative names: jj patch import and jj patch export.

Just a thought (don't give my suggestions more weight than others').

martinvonz avatar Dec 30 '24 00:12 martinvonz

jj patch sounds like a command to apply patch. It would be nice if there's a word that's obviously a noun.

yuja avatar Dec 30 '24 00:12 yuja

Would this be a subcommand for jj git?

joyously avatar Dec 30 '24 01:12 joyously

jj patch sounds like a command to apply patch. It would be nice if there's a word that's obviously a noun.

I think when coming from Git, this might trip somebody up, but "patch" is both a noun and a verb in English. I don't see a problem with patch WRT parts of speech, just onboarding.

ErichDonGubler avatar Dec 30 '24 01:12 ErichDonGubler

Would this be a subcommand for jj git?

No, it is a top-level command as dealing with patches isn't really Git specific. E.g Googles custom backend also needs to deal with it.

jj patch sounds like a command to apply patch. It would be nice if there's a word that's obviously a noun.

I honestly don't see a problem here, as it encompasses all patch like functionality.

PhilipMetzger avatar Dec 30 '24 10:12 PhilipMetzger

I honestly don't see a problem here, as it encompasses all patch like functionality.

It's nice if a subcommand namespace (= noun) isn't confusing with a command (= verb). That's the point. We already have jj tag, so I don't have a strong feeling about jj patch, though.

yuja avatar Dec 30 '24 12:12 yuja

Git has git am and git format-patch and git imap-send and git send-email and git bundle. Darcs has darcs apply and darcs rebase apply and darcs send. Breezy has brz git-apply and brz send. Mercurial has hg bundle (not sure about apply). I forgot to mention SVN has a patch command.

joyously avatar Dec 30 '24 16:12 joyously

I think when coming from Git, this might trip somebody up, but "patch" is both a noun and a verb in English. I don't see a problem with patch WRT parts of speech, just onboarding.

Personally, I think patch is fine as the namespace. The only actual Git command that has patch in the name is git format-patch, which is the noun rather than the verb.

Git has git am and git format-patch and git imap-send and git send-email and git bundle. Darcs has darcs apply and darcs rebase apply and darcs send. Breezy has brz git-apply and brz send. Mercurial has hg bundle (not sure about apply). I forgot to mention SVN has a patch command.

Thank for enumerating. I think it's pretty helpful to see what vocabulary other VCSes use.

  • It's interesting that they're not namespaced in a regular fashion in any of those VCSes.
  • Is bzr git-applyt he way to import a patch in bzr? It seems like a weird analogue for the command bzr send.
  • I personally think we should still namespace multiple commands under jj patch or similar.

arxanas avatar Jan 02 '25 00:01 arxanas

Is bzr git-applyt he way to import a patch in bzr? It seems like a weird analogue for the command bzr send.

Not bzr, which is Bazaar, but brz which is the modern fork Breezy which has the old Git compatibility plugin built-in. The help says

Apply a series of git-am style patches. This command will in the future probably be integrated into "bzr pull".

joyously avatar Jan 02 '25 00:01 joyously

Not bzr, which is Bazaar, but brz

My mistake; I actually read brz but habitually typed bzr somehow.

arxanas avatar Jan 02 '25 00:01 arxanas

Mercurial has hg bundle (not sure about apply).

Note hg (un)bundle uses hg's binary format (which is similar to the wire protocol). The equivalent is hg import, which has hg patch as an alias.

As a CLI design principle (originally from Olivia Mackall), hg doesn't do namespaced commands.

sunshowers avatar Feb 21 '25 19:02 sunshowers

Is there any other jj commands which could at least import patch files as a temporary workaround? (conflict resolution of jj applied on patch based workflow is pretty cool)

alberand avatar May 28 '25 11:05 alberand

I think you can use git am, etc. or patch -p0 can be used in colocated Git/jj repo. You might have to jj new <patch-base-revision first to apply patches cleanly, then rebase the changes.

yuja avatar May 28 '25 11:05 yuja

(conflict resolution of jj applied on patch based workflow is pretty cool)

This would be nice, but it only works if the patch has full context (-U1000000 should be sufficient in practice), or if we could find another commit where the patch applies cleanly.

martinvonz avatar May 28 '25 13:05 martinvonz

it only works if the patch has full context

ehh… It would be totally fine to drop the changes context couldn't be found for into a .rej file like git am --reject does. I just want the "conflicts can be resolved later" workflow instead of git am's stop-the-world one!

valpackett avatar Jul 22 '25 17:07 valpackett