ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/v0.9.0/design/tracking-branches.html

1655 lines
No EOL
46 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="canonical" href="https://martinvonz.github.io/jj/v0.9.0/design/tracking-branches.html">
<link rel="prev" href="git-submodule-storage.html">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.5.2, mkdocs-material-9.2.5">
<title>Tracking branches - Jujutsu docs</title>
<link rel="stylesheet" href="../assets/stylesheets/main.0e669242.min.css">
<script src="https://unpkg.com/iframe-worker/shim"></script>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr">
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#remotegit-tracking-branches" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Jujutsu docs" class="md-header__button md-logo" aria-label="Jujutsu docs" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Jujutsu docs
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Tracking branches
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Jujutsu docs" class="md-nav__button md-logo" aria-label="Jujutsu docs" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
Jujutsu docs
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_1" >
<label class="md-nav__link" for="__nav_1" id="__nav_1_label" tabindex="0">
<span class="md-ellipsis">
Getting started
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_1_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_1">
<span class="md-nav__icon md-icon"></span>
Getting started
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../install-and-setup.html" class="md-nav__link">
<span class="md-ellipsis">
Installation and Setup
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../tutorial.html" class="md-nav__link">
<span class="md-ellipsis">
Tutorial and Birds-Eye View
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../github.html" class="md-nav__link">
<span class="md-ellipsis">
Working with GitHub
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../FAQ.html" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Concepts
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Concepts
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../working-copy.html" class="md-nav__link">
<span class="md-ellipsis">
Working Copy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../branches.html" class="md-nav__link">
<span class="md-ellipsis">
Branches
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../conflicts.html" class="md-nav__link">
<span class="md-ellipsis">
Conflicts
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../operation-log.html" class="md-nav__link">
<span class="md-ellipsis">
Operation Log
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../glossary.html" class="md-nav__link">
<span class="md-ellipsis">
Glossary
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Configuration
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Configuration
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../config.html" class="md-nav__link">
<span class="md-ellipsis">
Settings
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../revsets.html" class="md-nav__link">
<span class="md-ellipsis">
Revset language
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../templates.html" class="md-nav__link">
<span class="md-ellipsis">
Templating language
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Comparisons
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Comparisons
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../git-comparison.html" class="md-nav__link">
<span class="md-ellipsis">
Git comparison
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../git-compatibility.html" class="md-nav__link">
<span class="md-ellipsis">
Git compatibility
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sapling-comparison.html" class="md-nav__link">
<span class="md-ellipsis">
Sapling
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../related-work.html" class="md-nav__link">
<span class="md-ellipsis">
Other related work
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" >
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0">
<span class="md-ellipsis">
Technical details
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6">
<span class="md-nav__icon md-icon"></span>
Technical details
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../technical/architecture.html" class="md-nav__link">
<span class="md-ellipsis">
Architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../technical/concurrency.html" class="md-nav__link">
<span class="md-ellipsis">
Concurrency
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../technical/conflicts.html" class="md-nav__link">
<span class="md-ellipsis">
Conflicts
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
<label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
<span class="md-ellipsis">
Contributing
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_7">
<span class="md-nav__icon md-icon"></span>
Contributing
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../contributing.html" class="md-nav__link">
<span class="md-ellipsis">
Guidelines and "How to...?"
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../code-of-conduct.html" class="md-nav__link">
<span class="md-ellipsis">
Code of conduct
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_8" checked>
<label class="md-nav__link" for="__nav_8" id="__nav_8_label" tabindex="0">
<span class="md-ellipsis">
Design docs
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_8_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_8">
<span class="md-nav__icon md-icon"></span>
Design docs
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="git-submodules.html" class="md-nav__link">
<span class="md-ellipsis">
git-submodules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="git-submodule-storage.html" class="md-nav__link">
<span class="md-ellipsis">
git-submodule-storage
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Tracking branches
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="tracking-branches.html" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Tracking branches
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#objective" class="md-nav__link">
Objective
</a>
</li>
<li class="md-nav__item">
<a href="#current-data-model-as-of-jj-080" class="md-nav__link">
Current data model (as of jj 0.8.0)
</a>
</li>
<li class="md-nav__item">
<a href="#proposed-data-model" class="md-nav__link">
Proposed data model
</a>
<nav class="md-nav" aria-label="Proposed data model">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mapping-to-the-current-data-model" class="md-nav__link">
Mapping to the current data model
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#common-command-behaviors" class="md-nav__link">
Common command behaviors
</a>
<nav class="md-nav" aria-label="Common command behaviors">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#fetchimport" class="md-nav__link">
fetch/import
</a>
</li>
<li class="md-nav__item">
<a href="#pushexport" class="md-nav__link">
push/export
</a>
</li>
<li class="md-nav__item">
<a href="#initclone" class="md-nav__link">
init/clone
</a>
</li>
<li class="md-nav__item">
<a href="#branch" class="md-nav__link">
branch
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#command-behavior-examples" class="md-nav__link">
Command behavior examples
</a>
<nav class="md-nav" aria-label="Command behavior examples">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#fetchimport_1" class="md-nav__link">
fetch/import
</a>
</li>
<li class="md-nav__item">
<a href="#pushexport_1" class="md-nav__link">
push/export
</a>
</li>
<li class="md-nav__item">
<a href="#git-remote" class="md-nav__link">
@git remote
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#remaining-issues" class="md-nav__link">
Remaining issues
</a>
</li>
<li class="md-nav__item">
<a href="#references" class="md-nav__link">
References
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#objective" class="md-nav__link">
Objective
</a>
</li>
<li class="md-nav__item">
<a href="#current-data-model-as-of-jj-080" class="md-nav__link">
Current data model (as of jj 0.8.0)
</a>
</li>
<li class="md-nav__item">
<a href="#proposed-data-model" class="md-nav__link">
Proposed data model
</a>
<nav class="md-nav" aria-label="Proposed data model">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mapping-to-the-current-data-model" class="md-nav__link">
Mapping to the current data model
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#common-command-behaviors" class="md-nav__link">
Common command behaviors
</a>
<nav class="md-nav" aria-label="Common command behaviors">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#fetchimport" class="md-nav__link">
fetch/import
</a>
</li>
<li class="md-nav__item">
<a href="#pushexport" class="md-nav__link">
push/export
</a>
</li>
<li class="md-nav__item">
<a href="#initclone" class="md-nav__link">
init/clone
</a>
</li>
<li class="md-nav__item">
<a href="#branch" class="md-nav__link">
branch
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#command-behavior-examples" class="md-nav__link">
Command behavior examples
</a>
<nav class="md-nav" aria-label="Command behavior examples">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#fetchimport_1" class="md-nav__link">
fetch/import
</a>
</li>
<li class="md-nav__item">
<a href="#pushexport_1" class="md-nav__link">
push/export
</a>
</li>
<li class="md-nav__item">
<a href="#git-remote" class="md-nav__link">
@git remote
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#remaining-issues" class="md-nav__link">
Remaining issues
</a>
</li>
<li class="md-nav__item">
<a href="#references" class="md-nav__link">
References
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="remotegit-tracking-branches">Remote/<code>@git</code> tracking branches<a class="headerlink" href="#remotegit-tracking-branches" title="Permanent link">&para;</a></h1>
<p>This is a plan to implement more Git-like remote tracking branch UX.</p>
<h2 id="objective">Objective<a class="headerlink" href="#objective" title="Permanent link">&para;</a></h2>
<p><code>jj</code> imports all remote branches to local branches by default. As described in
<a href="https://github.com/martinvonz/jj/issues/1136">#1136</a>, this doesn't interact nicely with Git if we have multiple Git remotes
with a number of branches. The <code>git.auto-local-branch</code> config can mitigate this
problem, but we'll get locally-deleted branches instead.</p>
<p>The goal of this plan is to implement
* proper support for tracking/non-tracking remote branches
* logically consistent data model for importing/exporting Git refs</p>
<h2 id="current-data-model-as-of-jj-080">Current data model (as of jj 0.8.0)<a class="headerlink" href="#current-data-model-as-of-jj-080" title="Permanent link">&para;</a></h2>
<p>Under the current model, all remote branches are "tracking" branches, and
remote changes are merged into the local counterparts.</p>
<div class="highlight"><pre><span></span><code>branches
[name]:
local_target?
remote_targets[remote]: target
tags
[name]: target
git_refs
[&quot;refs/heads/{name}&quot;]: target # last-known local branches
[&quot;refs/remotes/{remote}/{name}&quot;]: target # last-known remote branches
# (copied to remote_targets)
[&quot;refs/tags/{name}&quot;]: target # last-known tags
git_head: target?
</code></pre></div>
<ul>
<li>Remote branches are stored in both <code>branches[name].remote_targets</code> and
<code>git_refs["refs/remotes"]</code>. These two are kept in sync unless the branch is
removed by <code>jj branch forget</code> command.</li>
<li>Pseudo <code>@git</code> remote branches are stored in <code>git_refs["refs/heads"]</code>.</li>
</ul>
<h2 id="proposed-data-model">Proposed data model<a class="headerlink" href="#proposed-data-model" title="Permanent link">&para;</a></h2>
<p>We'll add a per-remote-branch <code>state</code> to distinguish non-tracking branches
from tracking ones.</p>
<div class="highlight"><pre><span></span><code>state = new # not merged in the local branch or tag
| tracking # merged in the local branch or tag
| forgotten # to be expunged on the next export
# `ignored` state could be added if we want to manage it by view, not by
# config file. target of ignored remote branch would be absent.
</code></pre></div>
<p>We'll add a per-remote view-like object to record the last known remote
branches. It will replace <code>git_refs</code> and <code>branches[name].remote_targets</code> in
the current model.</p>
<div class="highlight"><pre><span></span><code>branches
[name]: target
tags
[name]: target
remotes
[&quot;git&quot;]:
branches
[name]: target, state # refs/heads/{name}
tags
[name]: target, state = tracking # refs/tags/{name}
head: target?, state = TBD # refs/HEAD
[remote]:
branches
[name]: target, state # refs/remotes/{remote}/{name}
tags: (empty)
head: (empty)
</code></pre></div>
<p>With the proposed data model, we can
* naturally support remote branches which have no local counterparts
* deduplicate <code>branches[name].remote_targets</code> and <code>git_refs["refs/remotes"]</code>
* eliminate <code>git_</code> variables and methods from the view object</p>
<p>The <code>git.auto-local-branch</code> config knob is applied when importing new remote
branch. <code>jj branch</code> sub commands will be added to change the tracking state.</p>
<div class="highlight"><pre><span></span><code><span class="k">fn</span> <span class="nf">default_state_for_newly_imported_branch</span><span class="p">(</span><span class="n">config</span><span class="p">,</span><span class="w"> </span><span class="n">remote</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">remote</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s">&quot;git&quot;</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">Tracking</span>
<span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">config</span><span class="p">[</span><span class="s">&quot;git.auto-local-branch&quot;</span><span class="p">]</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">Tracking</span>
<span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">New</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</code></pre></div>
<p>A branch target to be merged is calculated based on the <code>state</code>.</p>
<div class="highlight"><pre><span></span><code><span class="k">fn</span> <span class="nf">target_in_merge_context</span><span class="p">(</span><span class="n">known_target</span><span class="p">,</span><span class="w"> </span><span class="n">state</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">state</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">New</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">RefTarget</span>::<span class="n">absent</span><span class="p">(),</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">Tracking</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">known_target</span><span class="p">,</span>
<span class="w"> </span><span class="n">State</span>::<span class="n">Forgotten</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">RefTarget</span>::<span class="n">absent</span><span class="p">(),</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</code></pre></div>
<h3 id="mapping-to-the-current-data-model">Mapping to the current data model<a class="headerlink" href="#mapping-to-the-current-data-model" title="Permanent link">&para;</a></h3>
<ul>
<li>New <code>remotes["git"].branches</code> corresponds to <code>git_refs["refs/heads"]</code>.</li>
<li>New <code>remotes["git"].tags</code> corresponds to <code>git_refs["refs/tags"]</code>.</li>
<li>New <code>remotes["git"].head</code> corresponds to <code>git_head</code>.</li>
<li>New <code>remotes[remote].branches</code> corresponds to
<code>git_refs["refs/remotes/{remote}"]</code> and <code>branches[].remote_targets[remote]</code>.</li>
<li>If <code>git_refs["refs/remotes/{remote}"]</code> exists but <code>.remote_targets</code> doesn't,
it means <code>state = forgotten</code> in new model.</li>
<li><code>state = new|tracking</code> doesn't exist in the current model. It's determined
by <code>git.auto-local-branch</code> config.</li>
</ul>
<h2 id="common-command-behaviors">Common command behaviors<a class="headerlink" href="#common-command-behaviors" title="Permanent link">&para;</a></h2>
<p>In the following sections, a merge is expressed as <code>adds - removes</code>.
In particular, a merge of local and remote targets is
<code>[local, remote] - [known_remote]</code>.</p>
<h3 id="fetchimport">fetch/import<a class="headerlink" href="#fetchimport" title="Permanent link">&para;</a></h3>
<ul>
<li>
<p><code>jj git fetch</code>
1. Fetches remote changes to the backing Git repo.
2. Import changes only for <code>remotes[remote].branches[glob]</code> (see below)</p>
<ul>
<li>TODO: how about fetched <code>.tags</code>?</li>
</ul>
</li>
<li>
<p><code>jj git import</code>
1. Calculates diff from the known <code>remotes</code> to the actual git repo.</p>
<ul>
<li><code>"refs/heads" - remotes["git"].branches</code></li>
<li><code>"refs/tags" - remotes["git"].tags</code></li>
<li><code>"HEAD" - remotes["git"].head</code> (unused)</li>
<li><code>"refs/remotes/{remote}" - remotes[remote]</code>
2. Merges diff in local <code>branches</code> and <code>tags</code> if <code>state</code> is <code>tracking</code>.</li>
<li>If the branch is new, the default <code>state</code> should be calculated.</li>
<li>If <code>state</code> is <code>forgotten</code>, the known branch is supposed to be removed,
and the default <code>state</code> should be calculated.
3. Updates <code>remotes</code> reflecting the import.</li>
<li><code>absent</code> entries are removed from <code>remotes</code>.
4. Abandons commits that are no longer referenced.</li>
</ul>
</li>
</ul>
<h3 id="pushexport">push/export<a class="headerlink" href="#pushexport" title="Permanent link">&para;</a></h3>
<ul>
<li>
<p><code>jj git push</code>
1. Calculates diff from the known <code>remotes[remote]</code> to the local changes.</p>
<ul>
<li><code>branches - remotes[remote].branches</code></li>
<li>If <code>state</code> is <code>new|forgotten</code> (i.e. untracked), the known remote
branch <code>target</code> is considered <code>absent</code>.</li>
<li>If <code>state</code> is <code>new|forgotten</code>, and if the local branch <code>target</code> is
<code>absent</code>, the diff <code>[absent, remote] - absent</code> is noop. So it's not
allowed to push deleted branch to untracked remote.</li>
<li>TODO: Copy Git's <code>--force-with-lease</code> behavior?</li>
<li>~<code>tags</code>~ (not implemented, but should be the same as <code>branches</code>)
2. Pushes diff to the remote Git repo (as well as remote tracking branches
in the backing Git repo.)
3. Sets <code>remotes[remote].branches[name].state = tracking</code>
4. Import changes only for <code>remotes[remote].branches[glob]</code></li>
</ul>
</li>
<li>
<p><code>jj git export</code>
1. Calculates diff from the known <code>remotes["git"]</code> to the local changes
and forgotten branches.</p>
<ul>
<li><code>branches - remotes["git"].branches</code> if <code>state</code> is <code>tracking</code></li>
<li>If <code>remotes["git"].branches[name]</code> is <code>absent</code>, the default
<code>state = tracking</code> applies.</li>
<li>If <code>state</code> is <code>forgotten</code> but local branch exists,
<code>remotes["git"].branches[name]</code> is supposed to be removed, and
the default <code>state = tracking</code> applies.</li>
<li>~<code>tags</code>~ (not implemented, but should be the same as <code>branches</code>)</li>
<li><code>absent - remotes[remote].branches</code> if <code>state</code> is <code>forgotten</code>
2. Applies diff to the backing Git repo.
3. Updates <code>remotes</code> reflecting the export.</li>
<li><code>absent</code> entries are removed from <code>remotes</code>.</li>
</ul>
</li>
</ul>
<h3 id="initclone">init/clone<a class="headerlink" href="#initclone" title="Permanent link">&para;</a></h3>
<ul>
<li><code>jj init</code></li>
<li>Import, track, and merge per <code>git.auto_local_branch</code> config.</li>
<li>
<p>If <code>!git.auto_local_branch</code>, no <code>tracking</code> state will be set.</p>
</li>
<li>
<p><code>jj git clone</code></p>
</li>
<li>Import, track, and merge per <code>git.auto_local_branch</code> config.</li>
<li>The default branch will be tracked regardless of <code>git.auto_local_branch</code>
config. (Because local branch is created for the default remote branch,
it makes sense to track.)</li>
</ul>
<h3 id="branch">branch<a class="headerlink" href="#branch" title="Permanent link">&para;</a></h3>
<ul>
<li><code>jj branch set {name}</code>
1. Sets local <code>branches[name]</code> entry.</li>
<li><code>jj branch delete {name}</code>
1. Removes local <code>branches[name]</code> entry.</li>
<li><code>jj branch forget {name}</code>
1. Removes local <code>branches[name]</code> entry if exists.
2. Sets all <code>remotes[remote].branches[name].state = forgotten</code>.</li>
<li><code>jj branch track {name}@{remote}</code> (new command)
1. Merges <code>[local, remote] - [absent]</code> in local branch.<ul>
<li>Same as "fetching/importing existing branch from untracked remote".
2. Sets <code>remotes[remote].branches[name].state = tracking</code>.</li>
</ul>
</li>
<li><code>jj branch untrack {name}@{remote}</code> (new command)
1. Sets <code>remotes[remote].branches[name].state = new</code>.</li>
<li><code>jj branch list</code></li>
<li>TODO: hide non-tracking branches by default? ...</li>
</ul>
<p>Note: desired behavior of <code>jj branch forget</code> is to
* discard both local and remote branches (without actually removing branches
at remotes)
* not abandon commits which belongs to those branches (even if the branch is
removed at a remote)</p>
<h2 id="command-behavior-examples">Command behavior examples<a class="headerlink" href="#command-behavior-examples" title="Permanent link">&para;</a></h2>
<h3 id="fetchimport_1">fetch/import<a class="headerlink" href="#fetchimport_1" title="Permanent link">&para;</a></h3>
<ul>
<li>Fetching/importing new branch
1. Decides new <code>state = new|tracking</code> based on <code>git.auto_local_branch</code>
2. If new <code>state</code> is <code>tracking</code>, merges <code>[absent, new_remote] - [absent]</code>
(i.e. creates local branch with <code>new_remote</code> target)
3. Sets <code>remotes[remote].branches[name].state</code></li>
<li>Fetching/importing existing branch from tracking remote
1. Merges <code>[local, new_remote] - [known_remote]</code></li>
<li>Fetching/importing existing branch from untracked remote
1. Decides new <code>state = new|tracking</code> based on <code>git.auto_local_branch</code>
2. If new <code>state</code> is <code>tracking</code>, merges <code>[local, new_remote] - [absent]</code>
3. Sets <code>remotes[remote].branches[name].state</code></li>
<li>Fetching/importing remotely-deleted branch from tracking remote
1. Merges <code>[local, absent] - [known_remote]</code>
2. Removes <code>remotes[remote].branches[name]</code> (<code>target</code> becomes <code>absent</code>)
(i.e. the remote branch is no longer tracked)
3. Abandons commits in the deleted branch</li>
<li>Fetching/importing remotely-deleted branch from untracked remote
1. Decides new <code>state = new|tracking</code> based on <code>git.auto_local_branch</code>
2. Noop anyway since <code>[local, absent] - [absent]</code> -&gt; <code>local</code></li>
<li>Fetching previously-forgotten branch from remote
1. Decides new <code>state = new|tracking</code> based on <code>git.auto_local_branch</code>
2. If new <code>state</code> is <code>tracking</code>, merges
<code>[absent, new_remote] - [absent]</code> -&gt; <code>new_remote</code>
(The known <code>target</code> of forgotten remote branch is <code>absent</code>)
3. Sets <code>remotes[remote].branches[name].state</code></li>
<li>Fetching forgotten and remotely-deleted branch</li>
<li>Same as "remotely-deleted branch from untracked remote" since <code>forgotten</code>
remote branch should never be <code>tracking</code></li>
<li>Therefore, no local commits should be abandoned</li>
</ul>
<h3 id="pushexport_1">push/export<a class="headerlink" href="#pushexport_1" title="Permanent link">&para;</a></h3>
<ul>
<li>Pushing/exporting new branch, remote doesn't exist
1. Exports <code>[local, absent] - [absent]</code> -&gt; <code>local</code>
2. Sets <code>remotes[remote].branches[name].state = tracking</code>
3. <code>import_refs()</code> merges <code>[local, local] - [absent]</code> -&gt; <code>local</code> (noop)</li>
<li>Pushing/exporting new branch, untracked remote exists
1. Exports <code>[local, remote] - [absent]</code><ul>
<li>Fails if <code>local</code> moved backwards or sideways
2. Sets <code>remotes[remote].branches[name].state = tracking</code>
3. <code>import_refs()</code> merges <code>[local, local] - [remote]</code> -&gt; <code>local</code> (noop)</li>
</ul>
</li>
<li>Pushing/exporting existing branch to tracking remote
1. Exports <code>[local, remote] - [remote]</code> -&gt; <code>local</code><ul>
<li>Fails if <code>local</code> moved backwards or sideways, and if <code>remote</code> is out of
sync
2. <code>import_refs()</code> merges <code>[local, local] - [remote]</code> -&gt; <code>local</code> (noop)</li>
</ul>
</li>
<li>Pushing/exporting existing branch to untracked remote</li>
<li>Same as "new branch"</li>
<li>Pushing/exporting deleted branch to tracking remote
1. Exports <code>[absent, remote] - [remote]</code> -&gt; <code>absent</code><ul>
<li>TODO: Fails if <code>remote</code> is out of sync?
2. <code>import_refs()</code> merges <code>[absent, absent] - [remote]</code> -&gt; <code>absent</code>
3. Removes <code>remotes[remote].branches[name]</code> (<code>target</code> becomes <code>absent</code>)</li>
</ul>
</li>
<li>Pushing/exporting deleted branch to untracked remote</li>
<li>Noop since <code>[absent, remote] - [absent]</code> -&gt; <code>remote</code></li>
<li>Perhaps, UI will report error</li>
<li>Pushing forgotten branch to untracked remote</li>
<li>Same as "deleted branch to untracked remote"</li>
<li>Exporting forgotten branch
1. Local branch change is noop since <code>[absent, absent] - [absent]</code> -&gt; <code>absent</code>
2. Exports <code>forgotten</code> state to the backing Git repo:
<code>[absent, known_remote] - [known_remote]</code> -&gt; <code>absent</code>
(This includes local branch in the pseudo <code>"git"</code> remote)
3. Removes <code>remotes[remote].branches[name]</code> (<code>target</code> becomes <code>absent</code>)</li>
<li>Pushing previously-forgotten branch to remote</li>
<li>Same as "new branch, untracked remote exists"</li>
<li>The known <code>target</code> of forgotten remote branch is <code>absent</code></li>
</ul>
<h3 id="git-remote"><code>@git</code> remote<a class="headerlink" href="#git-remote" title="Permanent link">&para;</a></h3>
<ul>
<li><code>jj branch untrack {name}@git</code></li>
<li>Maybe rejected (to avoid confusion)?</li>
<li>Allowing this would mean different local branches of the same name coexist
in jj and git.</li>
<li><code>jj git fetch --remote git</code></li>
<li>Maybe rejected (to avoid confusion)?</li>
<li>Conceptually, it's <code>git::import_refs()</code> only for local branches.</li>
<li><code>jj git push --remote git</code></li>
<li>Maybe rejected (to avoid confusion)?</li>
<li>Conceptually, it's <code>jj branch track</code> and <code>git::export_refs()</code> only for
local branches.</li>
</ul>
<h2 id="remaining-issues">Remaining issues<a class="headerlink" href="#remaining-issues" title="Permanent link">&para;</a></h2>
<ul>
<li><code>git.auto_local_branch = false</code> by default to help Git interop?</li>
<li>https://github.com/martinvonz/jj/issues/1862</li>
<li>https://github.com/martinvonz/jj/issues/1278 pushing to tracked remote</li>
<li>Option could be added to push to all <code>tracking</code> remotes?</li>
<li>Track remote branch locally with different name</li>
<li>Local branch name could be stored per remote branch</li>
<li>Consider UI complexity</li>
<li>"private" state (suggested by @ilyagr)</li>
<li>"private" branches can be pushed to their own remote, but not to the
upstream repo</li>
<li>This might be a state attached to a local branch (similar to Mercurial's
"secret" phase)</li>
</ul>
<h2 id="references">References<a class="headerlink" href="#references" title="Permanent link">&para;</a></h2>
<ul>
<li>https://github.com/martinvonz/jj/issues/1136</li>
<li>https://github.com/martinvonz/jj/issues/1666</li>
<li>https://github.com/martinvonz/jj/issues/1690</li>
<li>https://github.com/martinvonz/jj/issues/1734</li>
<li>https://github.com/martinvonz/jj/pull/1739</li>
</ul>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.dfff1995.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.78eede0e.min.js"></script>
</body>
</html>