Merge folders as branches when doing git svn clone

Viewed 35

How do we use the git svn clone to create multiple directories as branches and retain the branch name as is.

Here is the current svn structure

  • svn/url/projectrootfolder/code
    • Subfolder1
    • Subfolder2
  • svn/url/projectrootfolder/code_1
  • svn/url/projectrootfolder/code_2
  • svn/url/projectrootfolder/code_3

Run the following command with branches parameter (ignore code_2 and code_3)

echo svnpassword | git svn clone "svn/url/projectrootfolder" --trunk=code --branches=code_1 --no-metadata --authors-file="authors.txt" --prefix="svn/" --preserve-empty-dirs --placeholder-filename=.gitkeep --username svnreader ProjectLocalFolder

Check branch status

git branch -a

shows

* Master 
remotes/svn/Subfolder1
remotes/svn/Subfolder2
remotes/svn/trunk

I have only about a weeks worth experience with git and I assumed that the comamnd would create local branch code_1. But I don't see code_1 anywhere and the subfolders within the main project folder as branches. All the documentations I read seemed to indicate that git svn clone would achieve the desired result.

2 Answers

This repository has "non-standard" layout — there's no branches subdir; there's no trunk subdir.

To explain what the options do (you assumed it incorrectly); suppose we had an repo structured like this (another non-standard layout, for the sake of example):

.
├── deployed-copies
│   ├── tag-01
│   │   ├── docs
│   │   ├── src
│   │   └── test
│   ├── tag-02
│   │   ├── docs
│   │   ├── src
│   │   └── test
│   └── tag-03
│       ├── docs
│       ├── src
│       └── test
└── latest-code
    ├── docs
    ├── src
    └── test

Notice that by structure, this is almost the standard layout except with customized names: trunklatest-code, branchesdeployed-copies. (svn "tags" are not really tags in git terms.)

So, in this example, you'd use git svn clone --trunk=latest-code --branches=deployed-copies. It would create 4 git branches, svn/trunk, svn/tag-01, svn/tag-02, svn/tag-03 — and these will show in git branch -a.

Notice how this is different from your repo. I'm saying --branches=deployed-copies — not --branches=deployed-copies/tag-01 ! This is incorrect: --branches=code_1; the flag accepts the relpath of the parent directory — the one which stores all the branch-dirs — and is called branches/ in the standard layout.


Now, how to fix this? My advice would be:

By far, not all non-standard svn layouts are possible to configure via the commandline flags to git svn clone. The most branch mapping flexibility is achieved by editing the config.

@ulidtko - While I had figured I would have to go the config file route, thanks for clearing the understanding on the parent path. Even though I had read the documentation multiple times, this bit did not register and that was the missing link.

Merging this info and from other links I was able to arrive at the following course of actions that achieved what I needed.

  1. To initiate the project with the trunk

echo svnpassword | git svn clone "svn/url/projectrootfolder" --trunk=code --no-metadata --authors-file="authors.txt" --prefix="svn/" --preserve-empty-dirs --placeholder-filename=.gitkeep --username svnreader ProjectLocalFolder

  1. Add remote origin
git remote add origin git@ssh.dev.azure.com:v3/<<url>>
git fetch
git branch --set-upstream-to=origin/main master
git pull --rebase
git push origin HEAD:main
  1. Modify the .git/origin file and add this line to the svn-remote section
branches = /{code_1,code_2}/:refs/remotes/branches/*
git fetch
  1. The remote branches on svn should now show.

  2. Process with checking out/switching and then pushing those branches individually into git.

This seems to have done it for me.

Related