# [EGIT] [PATCH v2 1/1] Make sure to set up the default remote branch correctly

2 messages from 2009-02-23 to 2009-02-23. Participants: Ferry Huberts.
Thread: https://gitlist.dev/t/17973

## Ferry Huberts, 2009-02-23 17:45

Subject: [EGIT] [PATCH v2 0/1] Make sure to setup a clone the same as git-clone does
Message-ID: <cover.1235410609.git.ferry.huberts@pelagic.nl>
URL: https://gitlist.dev/e/cover.1235410609.git.ferry.huberts%40pelagic.nl

```
Currently the plugin does not setup the default remote branch, something that
git-clone does do.

This patch fixes the issue and makes the plugin setup a cloned repository
exactly the same as git-clone.

Ferry Huberts (1):
  Make sure to set up the default remote branch correctly

 .../org/spearce/egit/core/op/CloneOperation.java   |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

```

## Ferry Huberts, 2009-02-23 17:45

Subject: [EGIT] [PATCH v2 1/1] Make sure to set up the default remote branch correctly
Message-ID: <885442b0ed51a782b743aaef32e259ccd24429f4.1235410609.git.ferry.huberts@pelagic.nl>
URL: https://gitlist.dev/e/885442b0ed51a782b743aaef32e259ccd24429f4.1235410609.git.ferry.huberts%40pelagic.nl
In-Reply-To: <cover.1235410609.git.ferry.huberts@pelagic.nl>

```
This is to make sure that the plugin sets up a clone
in the same fashion as git-clone.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
---
 .../org/spearce/egit/core/op/CloneOperation.java   |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/op/CloneOperation.java b/org.spearce.egit.core/src/org/spearce/egit/core/op/CloneOperation.java
index 777894c..b66c870 100644
--- a/org.spearce.egit.core/src/org/spearce/egit/core/op/CloneOperation.java
+++ b/org.spearce.egit.core/src/org/spearce/egit/core/op/CloneOperation.java
@@ -32,6 +32,7 @@
 import org.spearce.jgit.lib.Ref;
 import org.spearce.jgit.lib.RefUpdate;
 import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.lib.RepositoryConfig;
 import org.spearce.jgit.lib.Tree;
 import org.spearce.jgit.lib.WorkDirCheckout;
 import org.spearce.jgit.transport.FetchResult;
@@ -158,6 +159,23 @@ private void doInit(final IProgressMonitor monitor)
 		local.getConfig().setBoolean("core", null, "bare", false);
 
 		remoteConfig.update(local.getConfig());
+
+		// branch is like 'Constants.R_HEADS + branchName',
+		// we need the 'branchName' part only
+		String[] branchSplit = branch.split(Constants.R_HEADS);
+		
+		// setup the default remote branch for branchName
+		local.getConfig().setString(
+				RepositoryConfig.BRANCH_SECTION,
+				branchSplit[branchSplit.length - 1],
+				"remote",
+				remoteName);
+		local.getConfig().setString(
+				RepositoryConfig.BRANCH_SECTION,
+				branchSplit[branchSplit.length - 1],
+				"merge",
+				branch);
+
 		local.getConfig().save();
 	}
 
-- 
1.6.0.6

```
