#10329

FR: `jj new` return new change id

OpenRosuavioopened 25d ago

Is your feature request related to a problem? Please describe.

I am wring a small script that uses jj for some automation. I need to create a new change with specific changes as parents to it and then move a bookmark to that new change. By the end of the script I want to be on the change the user was on when they started executed the script.

Describe the solution you'd like

Add and option to jj new to output the change id of the newly created change in a simple to use way for automations. The output should not require parsing to get just the change id.

Describe alternatives you've considered

--template for jj new

Give jj new (and other resource creating commands) a --template option.

Restore original

Right now my script roughly looks like...

  1. Get original change the original change and store it using jj show --no-patch --template 'self.change_id()'
  2. Create the new change and edit it
  3. Get the plain and full change id with jj show --no-patch --template 'self.change_id()'
  4. Update the bookmark
  5. ...
  6. Edit the stored original change.

This works, but it is state full and feels like it open more opportunities for errors in my script. If the scrip fails I have to restore the operation from before the script, so I have two different ways I could restore state. Also it add more ops to the op log.

Change id from op log

I remember reading that somewhere that I could get the change id from the op log after the jj new --no-edit command. I think it sounded more complex.

Parse the current ouput

I could try to parse the current output of the command, but that does not sound like it will lead to a reliable or stable solution.

Additional context

Activity

5
josephlou525d ago

Related #10077

See my comment for a hacky workaround: https://github.com/jj-vcs/jj/discussions/10077#discussioncomment-18195103

Right now my script roughly looks like...

  1. Get original change the original change and store it using jj show --no-patch --template 'self.change_id()'

Note that you should get the commit ID, not the change ID. For example, if @ is empty and has no description, then when you move away from it jj will consider it as "discardable" and immediately abandon it. That's how you can jj new all over the place without leaving a bunch of empty leaves throughout the tree. This means that when your script causes the working copy to move away, then the change ID associated with it might be abandoned, so your final jj edit "${original_change_id}" will no longer work (Error: Revision `xyz` doesn't exist). However, commit IDs stick around, so when you jj edit "${original_commit_id}" instead, the abandoned change will come back (with the same change ID).

josephlou525d ago

FWIW, I don't think jj new will get a --template flag. The current recommendations are thus the workaround I mentioned above (which is related to templates but isn't directly a template on jj new) or to wait for the planned scripting language, which would presumably have the equivalent of jj new but return a Commit object instead so you can get the change ID and stuff like that. (There is no tracking issue for that yet though.)

Rosuavio24d ago

Related #10077

See my comment for a hacky workaround: #10077 (comment)

Yeah I saw! Putting it into my script right now, thanks!

Rosuavio24d ago

For example, if @ is empty and has no description, then when you move away from it jj will consider it as "discardable" and immediately abandon it. That's how you can jj new all over the place without leaving a bunch of empty leaves throughout the tree.

That explains a lot, thanks!