From 581a513ebd2cbdc894592405209a477334702a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Mon, 13 Jun 2022 22:47:49 +0200 Subject: [PATCH] Initialize local branches on clone --- src/repo.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/repo.rs b/src/repo.rs index afda6ab..7b99179 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1548,6 +1548,24 @@ pub fn clone_repo( repo.rename_remote(&origin, &remote.name)?; } + // Initialize local branches. For all remote branches, we set up local + // tracking branches with the same name (just without the remote prefix). + for remote_branch in repo.remote_branches()? { + let local_branch_name = remote_branch.basename()?; + + if repo.find_local_branch(&local_branch_name).is_ok() { + continue; + } + + // Ignore /HEAD, as this is not something we can check out + if local_branch_name == "HEAD" { + continue; + } + + let mut local_branch = repo.create_branch(&local_branch_name, &remote_branch.commit()?)?; + local_branch.set_upstream(&remote.name, &local_branch_name)?; + } + // If there is no head_branch, we most likely cloned an empty repository and // there is no point in setting any upstreams. if let Ok(mut active_branch) = repo.head_branch() {