From 52678237a7d79a7e2a1bc70d7914d428f83e2d30 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 25 Aug 2021 15:25:44 -0700 Subject: [PATCH] cli: after cloning git repo, update to remote's HEAD --- README.md | 21 ++++++++++----------- src/commands.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 66c102684..ad58394f9 100644 --- a/README.md +++ b/README.md @@ -100,30 +100,26 @@ Now let's clone the same repo using `jj`: # repos yet) $ jj git clone https://github.com/martinvonz/jj.git jj-jj Fetching into new repo in "/jj-jj" +Working copy now at: 265ecf5cab2d $ cd jj-jj ``` Running `jj st` (short for`jj status`) now yields something like this: ```shell script $ jj st -Parent commit: 000000000000 -Working copy : 60c89901778d +Parent commit: 723ebb380971 cleanup: restructure escaped newlines to make new rustc happy +Working copy : 265ecf5cab2d The working copy is clean ``` -The `000000000000` commit is a virtual commit that's called the "root commit". -It's the root commit of every repo. The reason that it is our working copy's -parent is that `jj git clone` doesn't yet check out a particular commit. +We can see from the output above that our working copy has a commit id +(`265ecf5cab2d` in the example). -We can also see from the output above that our working copy has a commit id -(`60c89901778d` in the example). - -Let's check out a different commit so we get some files to work with in the -working copy: +Let's check out a particular commit, so we get more predicable output: ```shell script $ jj co 080a9b37ff7e Working copy now at: 608c179a60df -added 84 files, modified 0 files, removed 0 files +added 2 files, modified 57 files, removed 5 files $ jj st Parent commit: 080a9b37ff7e cli: make `jj st` show parent commit before working copy commit Working copy : 608c179a60df @@ -255,6 +251,9 @@ o 080a9b37ff7e 6a91b4ba16c7 martinvonz@google.com 2021-05-23 22:08:37.000 -07:00 o 000000000000 000000000000 1970-01-01 00:00:00.000 +00:00 ``` +(The `000000000000` commit is a virtual commit that's called the "root commit". +It's the root commit of every repo. The `root` symbol in the revset matches it.) + There are also operators for getting the parents (`:foo`), children `foo:`, ancestors (`,,foo`), descendants (`foo,,`), DAG range (`foo,,bar`, like `git log --ancestry-path`), range (`foo,,,bar`, like Git's `foo..bar`). There diff --git a/src/commands.rs b/src/commands.rs index 8a6e0b0dc..a513bdd4f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2800,7 +2800,16 @@ fn cmd_git_clone( CommandError::UserError(format!("Fetch failed: {:?}", err)) } })?; - tx.commit(); + if let Ok(fetch_head_ref) = git_repo.find_reference("FETCH_HEAD") { + if let Ok(fetch_head_git_commit) = fetch_head_ref.peel_to_commit() { + let fetch_head_id = CommitId(fetch_head_git_commit.id().as_bytes().to_vec()); + if let Ok(fetch_head_commit) = repo.store().get_commit(&fetch_head_id) { + tx.mut_repo().check_out(ui.settings(), &fetch_head_commit); + } + } + } + let repo = tx.commit(); + update_working_copy(ui, &repo, &repo.working_copy_locked())?; Ok(()) }