From: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> In order to share repository, the Git repository must be located outside the project. This patch extends the scope to the parent directory. Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/op/ConnectProviderOperation.java b/org.spearce.egit.core/src/org/spearce/egit/core/op/ConnectProviderOperation.java index b029de7..3ed3569 100644 --- a/org.spearce.egit.core/src/org/spearce/egit/core/op/ConnectProviderOperation.java +++ b/org.spearce.egit.core/src/org/spearce/egit/core/op/ConnectProviderOperation.java @@ -15,8 +15,10 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.team.core.RepositoryProvider; import org.spearce.egit.core.Activator; @@ -57,7 +59,7 @@ public class ConnectProviderOperation implements IWorkspaceRunnable { m.beginTask(CoreText.ConnectProviderOperation_connecting, 100); try { - final Collection repos = new ArrayList(); + final Collection<RepositoryMapping> repos = new ArrayList<RepositoryMapping>(); if (newGitDir != null) { try { @@ -68,8 +70,17 @@ public class ConnectProviderOperation implements IWorkspaceRunnable { db = new Repository(newGitDir); db.create(); + IPath gitDirParent = Path.fromOSString( + db.getDirectory().getAbsolutePath()) + .removeLastSegments(1); + IPath cPath = project.getLocation(); + String subset = null; + if (gitDirParent.isPrefixOf(cPath)) { + int n = cPath.matchingFirstSegments(gitDirParent); + subset = cPath.removeFirstSegments(n).toPortableString(); + } repos.add(new RepositoryMapping(project, db.getDirectory(), - null)); + subset)); db.close(); // If we don't refresh the project directory right diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java index 6f2c7cf..9ccf606 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java @@ -41,6 +41,9 @@ public class UIText extends NLS { public static String ExistingOrNewPage_createNew; /** */ + public static String ExistingOrNewPage_createInParent; + + /** */ public static String GitCloneWizard_title; /** */ diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/ExistingOrNewPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/ExistingOrNewPage.java index 24377d4..d0ddcb7 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/ExistingOrNewPage.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/ExistingOrNewPage.java @@ -19,6 +19,7 @@ import org.spearce.egit.ui.UIText; class ExistingOrNewPage extends WizardPage { final SharingWizard myWizard; + private Button createInParent; ExistingOrNewPage(final SharingWizard w) { super(ExistingOrNewPage.class.getName()); @@ -45,6 +46,7 @@ class ExistingOrNewPage extends WizardPage { public void widgetSelected(final SelectionEvent e) { myWizard.setUseExisting(); + createInParent.setEnabled(false); } }); useExisting.setSelection(true); @@ -59,9 +61,24 @@ class ExistingOrNewPage extends WizardPage { public void widgetSelected(final SelectionEvent e) { myWizard.setCreateNew(); + createInParent.setEnabled(true); } }); + createInParent = new Button(g, SWT.CHECK); + createInParent.setEnabled(createNew.getSelection()); + createInParent.setText(UIText.ExistingOrNewPage_createInParent); + createInParent.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) { + myWizard.setUseParent(createInParent.getSelection()); + } + }); + createInParent.setSelection(true); + myWizard.setUseParent(createInParent.getSelection()); setControl(g); } } diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/SharingWizard.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/SharingWizard.java index e02b038..292baf2 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/SharingWizard.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/sharing/SharingWizard.java @@ -36,6 +36,8 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { private File newGitDir; + private boolean useParent; + /** * Construct the Git Sharing Wizard for connecting Git project to Eclipse */ @@ -46,7 +48,14 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { public void init(final IWorkbench workbench, final IProject p) { project = p; - newGitDir = new File(project.getLocation().toFile(), ".git"); + calculateNewGitDir(); + } + + private void calculateNewGitDir() { + File pdir = project.getLocation().toFile(); + if (useParent) + pdir = pdir.getParentFile(); + newGitDir = new File(pdir, ".git"); } public void addPages() { @@ -100,4 +109,9 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { return false; } } + + void setUseParent(boolean selection) { + useParent = selection; + calculateNewGitDir(); + } } diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties index f4980a0..18f8c28 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties @@ -25,6 +25,7 @@ ExistingOrNewPage_description=Select Git Repository Location ExistingOrNewPage_groupHeader=Repository Location ExistingOrNewPage_useExisting=Search for existing Git repositories ExistingOrNewPage_createNew=Create a new Git repository for this project +ExistingOrNewPage_createInParent=Create repository in project's parent directory GitCloneWizard_title=Import Git Repository GitCloneWizard_jobName=Cloning from {0} -- 1.5.5.1.178.g1f811 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html