Skip to content

Instantly share code, notes, and snippets.

@eloots
Last active January 24, 2017 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eloots/5b1171dce2820830c2ac1cb37593c8cb to your computer and use it in GitHub Desktop.
Save eloots/5b1171dce2820830c2ac1cb37593c8cb to your computer and use it in GitHub Desktop.
Procedure to convert a koan based repo to a studentified style master repo

Note that in the this gist assumes that the following git aliases are in place:

        show-graph = log --graph --abbrev-commit --pretty=oneline
        co = checkout
        br = branch
        cm = commit
        st = status
        rb = rebase
        cp = cherry-pick
        lol = log --oneline

Clone the original repo

[ericloots@Eric-Loots-MBP] $ git clone git@github.com:typesafe-training/advanced-akka-java.git
Cloning into 'advanced-akka-java'...
X11 forwarding request failed on channel 0
remote: Counting objects: 322, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 322 (delta 10), reused 10 (delta 10), pack-reused 310
Receiving objects: 100% (322/322), 61.78 KiB | 0 bytes/s, done.
Resolving deltas: 100% (101/101), done.

[ericloots@Eric-Loots-MBP] $ cd advanced-akka-java/

The commit history looks as follows (note that there's a Base template commit that is of no use to us):

[ericloots@Eric-Loots-MBP] $ git lol
ea24155 Data replication
7a555c2 Persistent actors
da6d3b3 Cluster sharding
ac2b3b6 Cluster singleton
ef203f3 Cluster aware routers
a421b58 Cluster events
ee340ba Remoting
8a98458 Complete initial state
a2391cc Initial state (koan:initial)
90e6a83 Base template

Squash commits Initial state (koan:initial) and Base template together:

[ericloots@Eric-Loots-MBP] $ git rebase -i --root
[detached HEAD 2438ab4] Initial state (koan:initial)
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 11:25:04 2015 +0200
 32 files changed, 2327 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 LICENSE
 create mode 100644 README.md
 create mode 100644 build.sbt
 create mode 100644 man.sbt
 create mode 100644 project/build.properties


r 2438ab4 Initial state (koan:initial)


 create mode 100644 project/plugins.sbt
 create mode 100644 shell-prompt.sbt
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/BaseApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Game.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/GameEngine.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/GameEngineApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/PlayerRegistry.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/PlayerRegistryApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/RandomPlayer.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/ScoresRepository.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/ScoresRepositoryApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Settings.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/SharedJournalApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/SimplePlayer.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Terminal.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Tournament.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Utils.java
 create mode 100644 src/main/resources/application.conf
 create mode 100644 src/main/resources/logback.xml
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/GameTest.java
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/TournamentTest.java
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/UtilsTest.java
 create mode 100644 src/test/resources/README.md
 create mode 100644 src/test/resources/logback-test.xml
 create mode 100755 tags
 create mode 100755 verify
Successfully rebased and updated refs/heads/master.
/lbt/AAJ/advanced-akka-java
[ericloots@Eric-Loots-MBP] $ git lol
1f19cf6 Data replication
3cad7ca Persistent actors
c2bb835 Cluster sharding
d5091f5 Cluster singleton
136b7d3 Cluster aware routers
0ecb79f Cluster events
05fe4ec Remoting
01f0d30 Complete initial state
2438ab4 Initial state (koan:initial)

Change the commit messages for the resulting 8 commits to hold the respective exercise names (using the studentify naming conventions)

[ericloots@Eric-Loots-MBP] $ git rebase -i --root
[detached HEAD 6c60eea] exercise_000_initial_state


exercise_002_remoting
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 11:25:04 2015 +0200
 32 files changed, 2327 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 LICENSE


 create mode 100644 README.md
 create mode 100644 build.sbt
 create mode 100644 man.sbt
 create mode 100644 project/build.properties
 create mode 100644 project/plugins.sbt


exercise_004_cluster_aware_routers
 create mode 100644 shell-prompt.sbt
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/BaseApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Game.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/GameEngine.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/GameEngineApp.java


exercise_005_cluster_singleton
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/PlayerRegistry.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/PlayerRegistryApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/RandomPlayer.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/ScoresRepository.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/ScoresRepositoryApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Settings.java


exercise_006_cluster_sharding
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/SharedJournalApp.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/SimplePlayer.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Terminal.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Tournament.java
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/Utils.java
 create mode 100644 src/main/resources/application.conf


exercise_007_persistent_actors
 create mode 100644 src/main/resources/logback.xml
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/GameTest.java
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/TournamentTest.java
 create mode 100644 src/test/java/com/typesafe/training/akkacollect/UtilsTest.java
 create mode 100644 src/test/resources/README.md


exercise_008_data_replication
 create mode 100644 src/test/resources/logback-test.xml
 create mode 100755 tags
 create mode 100755 verify
[detached HEAD ede6f69] exercise_001_complete_initial_state
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 13:10:24 2015 +0200
 6 files changed, 82 insertions(+), 40 deletions(-)
 rewrite src/test/resources/README.md (91%)
[detached HEAD 2a3e6ad] exercise_002_remoting
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 14:18:05 2015 +0200
 10 files changed, 106 insertions(+), 95 deletions(-)
 rewrite src/test/resources/README.md (92%)
[detached HEAD 5160dd8] exercise_003_cluster_events
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 14:32:16 2015 +0200
 5 files changed, 144 insertions(+), 72 deletions(-)
 rewrite src/test/resources/README.md (73%)
[detached HEAD 541e85b] exercise_004_cluster_aware_routers
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 15:23:39 2015 +0200
 5 files changed, 82 insertions(+), 56 deletions(-)
 rewrite src/test/resources/README.md (94%)
[detached HEAD d364d0d] exercise_005_cluster_singleton
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 15:41:04 2015 +0200
 4 files changed, 138 insertions(+), 186 deletions(-)
 rewrite src/main/java/com/typesafe/training/akkacollect/GameEngine.java (69%)
 rewrite src/test/resources/README.md (65%)
[detached HEAD 3cbe069] exercise_006_cluster_sharding
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 16:10:36 2015 +0200
 9 files changed, 404 insertions(+), 52 deletions(-)
 create mode 100644 src/main/java/com/typesafe/training/akkacollect/PlayerSharding.java
 rewrite src/test/resources/README.md (66%)
[detached HEAD e4d0d22] exercise_007_persistent_actors
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 16:39:47 2015 +0200
 3 files changed, 146 insertions(+), 220 deletions(-)
 rewrite src/test/resources/README.md (88%)
[detached HEAD 051dc07] exercise_008_data_replication
 Author: Nilanjan Raychaudhuri <nraychaudhuri@gmail.com>
 Date: Wed Jun 24 16:49:46 2015 +0200
 3 files changed, 80 insertions(+), 56 deletions(-)
 rewrite src/test/resources/README.md (68%)
Successfully rebased and updated refs/heads/master.

The result now looks as follows for the AAJ course:

[ericloots@Eric-Loots-MBP] $ git lol
051dc07 exercise_008_data_replication
e4d0d22 exercise_007_persistent_actors
3cbe069 exercise_006_cluster_sharding
d364d0d exercise_005_cluster_singleton
541e85b exercise_004_cluster_aware_routers
5160dd8 exercise_003_cluster_events
2a3e6ad exercise_002_remoting
ede6f69 exercise_001_complete_initial_state
6c60eea exercise_000_initial_state

It would now be cool if this repo would meet the conditions for the delinearize command for converting a delinearized repo to the normal course master repo layout. Unfortunately, this isn't the case, as delinearize assumes that the project is (sbt) multi-project. Let's try to convert the repo to something that looks like what's needed...

Let's start by adding a common folder to each commit (holding at least one file, .gitignore in this case. We'll utilize git filter-branch to do the actual work.

First we create a shell script that will create a common directory with an empty .gitignore file in it:

[ericloots@Eric-Loots-MBP] $ ls -l /tmp/mkCommon
-rwxr-xr-x  1 ericloots  wheel  49 Jan 24 11:01 /tmp/mkCommon
[ericloots@Eric-Loots-MBP] $ cat /tmp/mkCommon
#!/bin/ksh

mkdir common
touch common/.gitignore

Now we can run filter-branch and quickly do a small verification:

[ericloots@Eric-Loots-MBP] $ git filter-branch --tree-filter /tmp/mkCommon -f
Rewrite 051dc07a5302354f5a19dd59b5357d44fcf8e998 (9/9) (1 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten

[ericloots@Eric-Loots-MBP] $ ls
LICENSE			build.sbt		man.sbt			shell-prompt.sbt	tags
README.md		common			project			src			verify
/lbt/AAJ/advanced-akka-java
[ericloots@Eric-Loots-MBP] $ git lol
6854272 exercise_008_data_replication
e193f6f exercise_007_persistent_actors
7bac4ec exercise_006_cluster_sharding
fdeff34 exercise_005_cluster_singleton
a53ae20 exercise_004_cluster_aware_routers
446cf41 exercise_003_cluster_events
f31d616 exercise_002_remoting
a1aa3af exercise_001_complete_initial_state
0b900bc exercise_000_initial_state

[ericloots@Eric-Loots-MBP] $ git co 0b900bc
Note: checking out '0b900bc'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 0b900bc... exercise_000_initial_state

[ericloots@Eric-Loots-MBP] $ ll -a common
total 0
drwxr-xr-x   3 ericloots  staff  102 Jan 24 11:01 .
drwxr-xr-x  14 ericloots  staff  476 Jan 24 11:01 ..
-rw-r--r--   1 ericloots  staff    0 Jan 24 11:01 .gitignore

[ericloots@Eric-Loots-MBP] $ git co master
Previous HEAD position was 0b900bc... exercise_000_initial_state
Switched to branch 'master'

Next step is to move the src folder in each commit to a new folder exercises. We'll do this using a mvSrc script that we'll run using git filter-branch:

[ericloots@Eric-Loots-MBP] $ more /tmp/mvSrc
#!/bin/ksh

mkdir exercises
mv src exercises

[ericloots@Eric-Loots-MBP] $ git filter-branch --tree-filter /tmp/mvSrc -f
Rewrite 68542729d748eaaa05795beda5716214bd3cad5e (5/9) (1 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten

[ericloots@Eric-Loots-MBP] $ ls exercises/
src

[ericloots@Eric-Loots-MBP] $ git lol
c904e35 exercise_008_data_replication
75e5f97 exercise_007_persistent_actors
088492e exercise_006_cluster_sharding
57ea266 exercise_005_cluster_singleton
b15679a exercise_004_cluster_aware_routers
5fab2ad exercise_003_cluster_events
c459aca exercise_002_remoting
dc46ab1 exercise_001_complete_initial_state
bcae73e exercise_000_initial_state

We're done with the linearized version of the course git repository. Now we need to build a dummy master repo (DMR) that matches the linearized repo. This DMR should meet a minimum number of requirements:

  • There must be README.md files with at least a single line of text under exercises_.../test/resources/README.md and common/test/resources/README.md
  • There must be a README.md under src/test/resources/README.md
  • There should be a valid multi-project build definition. Get inspiration from another 'studentified' master course and integrate what's in the original build definition
  • Create a .courseName file with a single line holding the name of the course

This results in the following folder structure:

[ericloots@Eric-Loots-MBP] $ ll
total 8
-rw-r--r--   1 ericloots  staff  2591 Jan 24 17:04 build.sbt
drwxr-xr-x   5 ericloots  staff   170 Jan 24 17:28 common
drwxr-xr-x   4 ericloots  staff   136 Jan 24 17:26 exercise_000_initial_state
drwxr-xr-x   4 ericloots  staff   136 Jan 24 17:28 exercise_001_complete_initial_state
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_002_remoting
drwxr-xr-x   4 ericloots  staff   136 Jan 24 17:31 exercise_003_cluster_events
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_004_cluster_aware_routers
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_005_cluster_singleton
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_006_cluster_sharding
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_007_persistent_actors
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:26 exercise_008_data_replication
drwxr-xr-x  14 ericloots  staff   476 Jan 24 17:14 project
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:16 src
drwxr-xr-x   3 ericloots  staff   102 Jan 24 17:14 target

[ericloots@Eric-Loots-MBP] $ ll project
total 80
-rw-r--r--  1 ericloots  staff  1903 Jan 24 17:11 AdditionalSettings.scala
-rw-r--r--  1 ericloots  staff  1955 Jan 24 17:03 CommonSettings.scala
-rw-r--r--  1 ericloots  staff   140 Jan 24 17:08 CompileOptions.scala
-rw-r--r--  1 ericloots  staff  2204 Jan 24 17:09 Dependencies.scala
-rw-r--r--  1 ericloots  staff  3395 Jan 24 17:12 Man.scala
-rw-r--r--  1 ericloots  staff   731 Jan 24 17:13 Navigation.scala
-rw-r--r--  1 ericloots  staff   449 Jan 24 17:12 StudentKeys.scala
-rw-r--r--  1 ericloots  staff  1108 Jan 24 17:11 StudentsCommandsPlugin.scala
-rw-r--r--  1 ericloots  staff    20 Jan 24 17:01 build.properties
-rw-r--r--  1 ericloots  staff   136 Jan 24 17:14 plugins.sbt
drwxr-xr-x  3 ericloots  staff   102 Jan 24 17:14 project
drwxr-xr-x  6 ericloots  staff   204 Jan 24 17:14 target
[ericloots@Eric-Loots-MBP] $

One can now delinearize the prepared koan style project into the dummy master.

Next-up is verifying that everything works as expected

PS: Not related to the above: when running a script with filter-branch, one can access the SHA from the commit being processed via the variable GIT_COMMIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment