Skip to content

Instantly share code, notes, and snippets.

@peteruhnak
Last active August 18, 2017 12:31
Show Gist options
  • Save peteruhnak/639af246b58c94416f78 to your computer and use it in GitHub Desktop.
Save peteruhnak/639af246b58c94416f78 to your computer and use it in GitHub Desktop.
Copy a project from SmalltalkHub to GitHub
"Based on Uko's script https://gist.github.com/Uko/6898022"
"Get reference to the source repository"
source := MCSmalltalkhubRepository allInstances detect: [ :each |
each location includesSubstring: 'StName/project-name'
].
"Get reference to the target repository"
destination := MCFileTreeGitRepository allInstances detect: [ :each |
each location includesSubstring: 'project-name/repository'
].
"Setup name mapping from Monticello commits to git commits."
MCFileTreeGitRepository
namesAt: 'MonticelloCommitName' put: 'Full Name' email: '<your.mail@example.com>';
namesAt: 'PeterUhnak' put: 'Peter Uhnak' email: '<i.uhnak@gmail.com>'.
"Setup Gofer"
goSource := Gofer new repository: source.
goDestination := Gofer new repository: destination.
"The packages obtained from Gofer are in random order... so some sorting has to be done so the git history is nicer."
sortBlock := [ :x : y |
(x second = y second) ifTrue: [ x fourth asNumber <= y fourth asNumber ]
ifFalse: [ x second < y second ].
].
"My-Package-Author.Number"
re := '^(.+)-([^-]+)\.(\d+)$' asRegex.
fileBlocks := source allVersionNames collect: [ :each |
re search: each.
{
re subexpression: 1. "first - full string"
re subexpression: 2. "second - package name"
re subexpression: 3. "third - author name"
re subexpression: 4. "fourth - commit name"
}
].
filesSorted := fileBlocks asSortedCollection: sortBlock.
files := (filesSorted collect: [ :x | x first ]) asArray.
(goSource allResolved select: [ :resolved | files anySatisfy: [ :each |
resolved name = each ] ]) do: [ :each | goSource package: each packageName ].
goSource fetch. "downloads all mcz on your computer"
destinationFiles := destination allVersionNames. "checks what files are already at destination"
files reject: [ :file | destinationFiles includes: file ] thenDo: [ :file |
goDestination version: file ]. "selects only the mcz that are not yet at destination"
goDestination push. "sends everything to new repository"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment