Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: jj diff --remote #4756

Open
Grillo-0 opened this issue Nov 2, 2024 · 8 comments · May be fixed by #5450
Open

FR: jj diff --remote #4756

Grillo-0 opened this issue Nov 2, 2024 · 8 comments · May be fixed by #5450
Labels
enhancement New feature or request

Comments

@Grillo-0
Copy link
Contributor

Grillo-0 commented Nov 2, 2024

Is your feature request related to a problem? Please describe.
Sometimes I change my local branch and I want to see what changed on the remote before pushing. Currently, I've being doing jj diff --from <bookmark-name>@<remote> --to <bookmark-name>. I would find it much easier if I don't need to remember the bookmark name and type it twice.

Describe the solution you'd like
I think that a new flag called --remote could solve this. If the head is on a tracked bookmark, it would diff the remote with the local.

Describe alternatives you've considered
Maybe this could be solved with new revsets functions? Maybe a bookmark_name() to return the bookmark name of a revision, so you could use with remote_branches().

@yuja
Copy link
Contributor

yuja commented Nov 3, 2024

I feel --remote is too specific. It only works if the revision to be diffed has one tracking branch. Maybe better to add some revset function/parameter that looks up tracking remote by local revision.

@yuja yuja added the enhancement New feature or request label Nov 3, 2024
@zx8
Copy link

zx8 commented Dec 13, 2024

Landed here searching for "how to diff jj remote changes"

I'm trying to replicate my old git flow, and when using git I got into the habit of always doing a git diff '@{upstream}' prior to pushing any actual changes to the remote, to ensure what I was pushing was actually what I intended push (i.e. no secrets or unintended files included).

This is even more relevant for me with jj, given the auto-snapshotting behaviour. Is there absolutely no way (e.g. alias) to do this currently?

@david-crespo
Copy link
Contributor

I ran into this yesterday and came up with a goofy workaround. I'm sure there's a way to clean it up, and I'm sure there are lots of edge cases around, e.g., multiple bookmarks between main and @, but it is working for me in simple cases.

function curr_bookmark { jj bookmark list --tracked -r 'trunk()..@' -T 'name++"\n"' | head -1 }
alias jdr='jj diff -f "$(curr_bookmark)@origin"'

@arxanas
Copy link
Contributor

arxanas commented Dec 13, 2024

This is even more relevant for me with jj, given the auto-snapshotting behaviour. Is there absolutely no way (e.g. alias) to do this currently?

Since jj doesn't have a "currently-checked-out branch" (yet?), there's fundamentally no way to ask "what is the current branch" so that you can compare it to its remote counterpart. I think @david-crespo's solution above is the best you can do for now, where you have to heuristically determine what branch you're on.

@0xdeafbeef
Copy link
Member

This is even more relevant for me with jj, given the auto-snapshotting behaviour. Is there absolutely no way (e.g. alias) to do this currently?

Since jj doesn't have a "currently-checked-out branch" (yet?), there's fundamentally no way to ask "what is the current branch" so that you can compare it to its remote counterpart. I think @david-crespo's solution above is the best you can do for now, where you have to heuristically determine what branch you're on.

What you think about jj diff - -branch name - - remote
You will need to type less and you don't need any heuristics. Just diff branch with branch@remote

@david-crespo
Copy link
Contributor

The point is to not have to figure out and type the bookmark name.

@bryceberger
Copy link
Member

Wrote a script to cover the case of "diff from my local commit to corresponding commit on remote".

#!/usr/bin/env bash
set -eu -o pipefail

target=$1

# todo: configurable stream head
bookmark_names=$(jj log --no-graph -r 'heads(::@ & bookmarks())' -T 'local_bookmarks.map(|l| l.name()).join(" ")')
IFS=" " read -ra bookmarks <<<"$bookmark_names"
# todo: error message
[ ${#bookmarks[@]} -eq 1 ] || exit 1
bookmark=${bookmarks[0]}

all_refs=$(jj evolog --no-graph -T 'commit_id ++ "|"' -r "$target")
# todo: configurable remote
remote=$(jj log --no-graph -T 'commit_id' -n 1 -r "($all_refs none()) & ::$bookmark@origin")

jj diff --from "$remote" --to "$target"

It gets somewhat confused if you split a commit, and you might want to use jj interdiff instead of jj diff. Could also just stop at the bookmark=... line if you just want to jj diff --from bookmark@remote --to bookmark.

@Grillo-0
Copy link
Contributor Author

Grillo-0 commented Jan 23, 2025

I'm was working on a PR to try to fix this. I followed @yuja comment and created a remote revset function. With it, you can do jj diff --from remote(@) --to @

I wrote most of the code a while ago, but didn't get around to finish it due to university and work, but now that I see that more people would like to have this issue fixed, I might have the will to finish it.

Grillo-0 added a commit to Grillo-0/jj that referenced this issue Jan 23, 2025
This can be used to find the remote bookmark tracked by a revset.

It can be useful for diffing with the remote:
`jj diff --from remote(@) --to @`

Fixes: jj-vcs#4756
@Grillo-0 Grillo-0 linked a pull request Jan 23, 2025 that will close this issue
4 tasks
Grillo-0 added a commit to Grillo-0/jj that referenced this issue Jan 24, 2025
This can be used to find the remote bookmark tracked by a revset.

It can be useful for diffing with the remote:
`jj diff --from remote(@) --to @`

Fixes: jj-vcs#4756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants