2009-05-22 25 views
7

Ho iniziato a utilizzare git-svn perché alcuni dei miei lavori siano in grado di eseguire commit locali. Funziona alla grande per i progetti che utilizzano il layout svn standard. Recentemente ho iniziato a lavorare su un progetto Java diviso in più moduli connessi (20-25), e ogni modulo ha la propria cartella radice nello stesso repository SVN con i propri trunk/rami/tag.Più progetti svn in un unico repository git?

svnrepo/  
    module-1 
    trunk 
    branches 
    tags 
    module-N 
    trunk 
    branches 
    tags 

Ho clonato ogni modulo con git svn clone -s/path/to/svnrepo/modulo [1-N]. Il "problema" è che quando voglio fare git svn rebase su tutti i moduli devo farlo N volte.

Ho provato a fare git svn clone/percorso/a/svnrepo/evitare di fare l'operazione rebase N volte, ma questo mi lascia con un layout di directory che è lo stesso del repository SVN.

C'è un modo per tenere traccia di tutti i tronchi di tutti i moduli in un repository git? In modo che ottenga un layout di directory come questo nel mio repository git:

module-1 
module-2 
module-N 
+0

Looks come un duplicato di http://stackoverflow.com/questions/279144/clone-multiple-svn-projects-with-git-svn – Wernight

+0

Questa altra domanda non riguarda l'unione dei progetti svn nello stesso repository git. –

risposta

2

Sfortunatamente no, non c'è modo di farlo. Un problema è che non c'è nulla che impedisca a due o più moduli di avere un ramo con lo stesso nome. Quindi, in git-svn, quando gli dai il nome del ramo, come potrebbe sapere di quale modulo stai parlando?

Questo problema deriva in realtà dal fatto che i rami di Subversion non sono un concetto di prima classe, mentre in git lo sono. git-svn è in grado di usare più o meno un kludge per aggirare questo fatto, ma il kludge si rompe se il repository ha un layout "non standard" (come quello con cui si sta lavorando).

Il mio consiglio: scrivere una sceneggiatura a git-svn rebase tutte.

+2

Penso che il suo layout sia standard. – IttayD

+0

Inoltre, qual è il problema?Avrà due telecomandi, uno nominato modulo-1 l'altro modulo-2, quindi i rami sono module-1/somebranch e module-2/somebranch – IttayD

+0

@IttayD: No, non penso che sia un layout standard. Nel layout standard previsto da git-svn, esiste un solo trunk, un tag e un ramo. Il suo layout ha N di ciascuno. In secondo luogo, quando si clona l'intero repository SVN, ciascun modulo non diventa un telecomando. Quindi, il problema è esattamente come dice lui: ottiene un singolo repository Git che rispecchia esattamente la struttura della directory SVN. –

0

Mi sono ritrovato nello stesso problema con te e ho scoperto che non esiste un modo standard per farlo. Tuttavia, guardandomi attorno ho scoperto una strategia per aiutare a farlo, e ho creato uno script di power shell basato su questo. Non riesco a ricordare la fonte, o darei loro credito. Lo spiegherei, ma è più facile vedere solo la sceneggiatura e i commenti.

È possibile utilizzare questo script o, se non si utilizza Windows/PowerShell, eseguire su basato su di esso. La cosa buona è che una volta che hai i tuoi repository git individuali per ogni sottomodulo, se qualcosa fallisce, è veramente veloce/facile eliminare semplicemente il nuovo repo "master" git, apportare modifiche allo script ed eseguirlo di nuovo, dato che è tutto Locale.

Attenzione, ci sono alcuni casi che non vengono gestiti, come quando un sottomodulo ha una cartella che è chiamata la stessa di un altro sottomodulo (quindi se si ha un sottomodulo chiamato BIN e poi gli altri sub moduli hanno sub una sottocartella BIN, fallirà). Assicurati inoltre che tutti i tuoi repository git sub siano aggiornati prima di iniziare!

È possibile controllare lo script in questo gist: Gist Script

se per qualche motivo il succo è giù, ho aggiunto anche qui (anche se molto meno leggibile)

$GitReposLocation = "path\to\individual\git\repos"; #1 git repo for each module (you svn cloned each one using std layout) 
$MasterGitRepoLocation = "path\to\masterRepo"; #the path where you want your main repo that contains all the modules 
git reset --hard; 

write-host Creating folder $MasterGitRepoLocation -foregroundcolor "green"; 
mkdir $MasterGitRepoLocation; 

write-host Moving to folder $MasterGitRepoLocation -foregroundcolor "green"; 
cd $MasterGitRepoLocation; 

write-host Creating Git Repository -foregroundcolor "cyan"; 
git init; 

#this is hacky, but we need to have an initial commit 
"" > root; 
git add root; 
write-host Creating root node -foregroundcolor "cyan"; 
git commit -m "Initial commit to create parent root."; 

#we are going to be moving files around, and don't want to move the files we already got in our MasterRepo root/workspace 
$NotMoveThesFiles = @(); 
dir |%{[email protected]($_.FullName) }; 

$repos = @(); 
# you should add a repo here if for some reasong you don't want to process that one. 
# [email protected]("SomeRepo"); 

dir -Path $GitReposLocation -Directory |Where-object{ $repos -NotContains $_.Name }|%{[email protected]($_.Name) }; 

# for-each repo.... 
$repos|%{ 
     $SubRepoName = $_; 
     write-host Processing GitRepo $SubRepoName -foregroundcolor "green";   
     $Remote = "remote"+$SubRepoName;   

     #add this git repo (of a module) as a remote of our main repo 
     write-host Adding reference to $SubRepoName as remote repo -foregroundcolor "cyan"; 
     git remote add -f $Remote $GitReposLocation\$SubRepoName; 

     #Merge that sub repo into the main repo. The only problem? It will copy that repo's workspace 
     #directly into our main repo Root folder 
     write-host Merging remote$SubRepoName/master into master -foregroundcolor "cyan"; 
     git merge remote$SubRepoName/master; 

     #so now we are going to create a folder with the name of this module (subRepo) 
     #and move everything that is in the Master's root folder to that folder, except of course 
     #things that we already had in the root folder before the merge. (in the NotMoveTheseFiles array) 

     write-host Moving files got from $SubRepoName to a subdir called $SubRepoName -foregroundcolor "green"; 

     #create folder folr the module 
     mkdir $SubRepoName; 
     #add these new folde to the list of things we don't want to move into it. 
     [email protected]($SubRepoName); 

     #copy all files not in the NotMoveTheseFiles array into the newly created folder. 
     dir |where-object {$NotMoveThesFiles -NotContains $_} |%{git mv $_ $SubRepoName}; 

     #commit the change where we moved all these files around. 
     $CommitMessage = "Moving files got from " + $SubRepoName + " to a subdir called $SubRepoName" 
     git commit -m $CommitMessage; 
    } 
Problemi correlati