diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c5bf7af1..f948825b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index a6f980c6f4..08b84189f8 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -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", @@ -382,4 +382,4 @@ } } } -} \ No newline at end of file +} diff --git a/cli/tests/test_git_fetch.rs b/cli/tests/test_git_fetch.rs index d7e7a098bf..073b7dc5f6 100644 --- a/cli/tests/test_git_fetch.rs +++ b/cli/tests/test_git_fetch.rs @@ -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(); diff --git a/docs/config.md b/docs/config.md index ebd3fd6cc4..955a355ee0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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 diff --git a/docs/design/tracking-branches.md b/docs/design/tracking-branches.md index fc3b54b4d4..68aaf21df9 100644 --- a/docs/design/tracking-branches.md +++ b/docs/design/tracking-branches.md @@ -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 diff --git a/docs/github.md b/docs/github.md index f8c50dd949..a50af917db 100644 --- a/docs/github.md +++ b/docs/github.md @@ -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 ` 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 @` 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 ` instead of `jj new @`. You can find more information on that setting [here][auto-branch]. diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 3584ab16c0..a072328398 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -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), @@ -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, } }