Skip to content

Commit

Permalink
git: turn git.auto-local-branch off by default
Browse files Browse the repository at this point in the history
As far as I can see in the chat, there's no objection to changing the default,
and git.auto-local-branch = false is generally preferred.

docs/branches.md isn't updated as it would otherwise conflict with #2625. I
think the "Remotes" section will need a non-trivial rewrite.

#1136, #1862
  • Loading branch information
yuja committed Dec 16, 2023
1 parent 6817f2c commit 09fce5a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking changes

* `jj git fetch` no longer imports new remote branches as local branches. Set
`git.auto-local-branch = true` to restore the old behavior.

### New features

* Information about new and resolved conflicts is now printed by every command.
Expand Down
4 changes: 2 additions & 2 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"auto-local-branch": {
"type": "boolean",
"description": "Whether jj creates a local branch with the same name when it imports a remote-tracking branch from git. See https://github.com/martinvonz/jj/blob/main/docs/config.md#automatic-local-branch-creation",
"default": true
"default": false
},
"abandon-unreachable-commits": {
"type": "boolean",
Expand Down Expand Up @@ -382,4 +382,4 @@
}
}
}
}
}
13 changes: 13 additions & 0 deletions cli/tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ fn get_log_output(test_env: &TestEnvironment, workspace_root: &Path) -> String {
test_env.jj_cmd_success(workspace_root, &["log", "-T", template, "-r", "all()"])
}

#[test]
fn test_git_fetch_with_default_config() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");

test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin@origin: oputwtnw ffecd2d6 message
"###);
}

#[test]
fn test_git_fetch_default_remote() {
let test_env = TestEnvironment::default();
Expand Down
10 changes: 5 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@ conflict is considered fully resolved when there are no conflict markers left.

### Automatic local branch creation

By default, when `jj` imports a new remote-tracking branch from Git, it also
creates a local branch with the same name. In some repositories, this
may be undesirable, e.g.:
When `jj` imports a new remote-tracking branch from Git, it can also create a
local branch with the same name. This feature is disabled by default because it
may be undesirable in some repositories, e.g.:

- There is a remote with a lot of historical branches that you don't
want to be exported to the co-located Git repo.
- There are multiple remotes with conflicting views of that branch,
resulting in an unhelpful conflicted state.

You can disable this behavior by setting `git.auto-local-branch` like so,
You can enable this behavior by setting `git.auto-local-branch` like so,

```toml
git.auto-local-branch = false
git.auto-local-branch = true
```

This setting is applied only to new remote branches. Existing remote branches
Expand Down
2 changes: 0 additions & 2 deletions docs/design/tracking-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ Note: desired behavior of `jj branch forget` is to

## Remaining issues

* `git.auto_local_branch = false` by default to help Git interop?
* https://github.com/martinvonz/jj/issues/1862
* https://github.com/martinvonz/jj/issues/1278 pushing to tracked remote
* Option could be added to push to all `tracking` remotes?
* Track remote branch locally with different name
Expand Down
14 changes: 8 additions & 6 deletions docs/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ The hyphen after `your-feature` comes from the

## Working with other people's branches

By default `jj git clone` and `jj git fetch` clone all active branches from
the remote. This means that if you want to iterate or test another
contributor's branch you can `jj new <branchname>` onto it.

If your remote has a large amount of old, inactive branches or this feature is
undesirable, set `git.auto-local-branch = false` in the config file.
By default, `jj git clone` imports the default remote branch (which is usually
`main` or `master`), but `jj git fetch` doesn't import new remote branches to
local branches. This means that if you want to iterate or test another
contributor's branch, you'll need to do `jj new <branch>@<remote>` onto it.

If you want to import all remote branches including inactive ones, set
`git.auto-local-branch = true` in the config file. Then you can specify a
contributor's branch as `jj new <branch>` instead of `jj new <branch>@<remote>`.

You can find more information on that setting [here][auto-branch].

Expand Down
4 changes: 2 additions & 2 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct GitSettings {
impl GitSettings {
pub fn from_config(config: &config::Config) -> Self {
GitSettings {
auto_local_branch: config.get_bool("git.auto-local-branch").unwrap_or(true),
auto_local_branch: config.get_bool("git.auto-local-branch").unwrap_or(false),
abandon_unreachable_commits: config
.get_bool("git.abandon-unreachable-commits")
.unwrap_or(true),
Expand All @@ -58,7 +58,7 @@ impl GitSettings {
impl Default for GitSettings {
fn default() -> Self {
GitSettings {
auto_local_branch: true,
auto_local_branch: false,
abandon_unreachable_commits: true,
}
}
Expand Down

0 comments on commit 09fce5a

Please sign in to comment.