martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
9.03k stars 313 forks source link

`jj undo` apparently "undid" automatic git-refs import (but may have simply done nothing) #4625

Open BatmanAoD opened 3 weeks ago

BatmanAoD commented 3 weeks ago

Description

According to the op log, I ran jj undo, and it did an import git refs immediately followed by "undoing" that import, which doesn't make sense.

Steps to Reproduce the Problem

  1. Do something undo-able (e.g. jj abandon)
  2. Make a change in git that must be imported
  3. jj undo

Expected Behavior

Step one is undone.

Actual Behavior

Apparently a no-op. jj op log shows:

○  0ad61fffcb63 kstrand@RM-LOSX-0F2WP14 29 seconds ago, lasted 9 milliseconds
│  undo operation d90b70abbd980b9e82885f150cb7d1c469ace0c998539212f273e199f5b19418d0dd3b7853e52bee727826576499eec4c404c8934b519f62a150cf98170ab455
│  args: jj undo
○  d90b70abbd98 kstrand@RM-LOSX-0F2WP14 29 seconds ago, lasted 43 milliseconds
│  import git refs
│  args: jj undo
○  336abf42c84e kstrand@RM-LOSX-0F2WP14 12 minutes ago, lasted 29 milliseconds
│  abandon commit 9650f41f53d3a36f299042afbfa1e26f1e61428a
│  args: jj abandon

The second jj undo node claims to "undo" the import git refs node. I'm pretty sure the import is not reversible, though.

Specifications

martinvonz commented 3 weeks ago

The import can be undone. For example, lets say you had moved a branch in git, and you then run jj undo. That will import the moved branch and then immediately undo it. It will also export the changes back to Git. Like this:

$ jj log
@  m martinvonz@google.com 2024-10-11 12:49:07 125bcd2a
│  (empty) (no description set)
○  v martinvonz@google.com 2024-10-11 12:47:30 main HEAD@git f3421f8e
│  bar
○  r martinvonz@google.com 2024-10-11 12:47:06 0dfbd820
│  foo
◆  z root() 00000000

$ git branch -f main 0dfbd820

$ jj undo
Abandoned 1 commits that are no longer reachable.
Rebased 1 descendant commits off of commits rewritten from git
Working copy now at: m c92ce1fb (empty) (no description set)
Parent commit      : r 0dfbd820 main | foo
Added 0 files, modified 1 files, removed 0 files
Done importing changes from the underlying Git repo.
Undid operation 4fb019417b7b now, lasted 668 milliseconds import git refs
Working copy now at: m 125bcd2a (empty) (no description set)
Parent commit      : v f3421f8e main | bar
Added 0 files, modified 1 files, removed 0 files

$ jj log
@  m martinvonz@google.com 2024-10-11 12:49:07 125bcd2a
│  (empty) (no description set)
○  v martinvonz@google.com 2024-10-11 12:47:30 main HEAD@git f3421f8e
│  bar
○  r martinvonz@google.com 2024-10-11 12:47:06 0dfbd820
│  foo
◆  z root() 00000000
BatmanAoD commented 3 weeks ago

Huh. That's not what I would have expected, but it makes some sense that jj would be able to reverse things you did in git. But I don't actually know in this case what was being undone; I think it was just a git fetch, but I don't remember intentionally doing anything with git.

How much "undoing" is possible? If I make five new commits with git, without running any jj commands, and then run jj undo, does it import and then "hide" all five commits?