Skip to content

Repository Management

neitsa edited this page Dec 26, 2016 · 5 revisions

We use Git subtree commands to handle the RemoteTech-Complete repository as it is composed of the other repositories in the RemoteTechnologiesGroup organisation.

Adding a new subtree

First we need to add a remote for the subtree. The command is:

$ git remote add <friendly_name> <repo_url>

Example with RemoteTech-Common:

Neitsa@Falcon /RemoteTech-Complete (develop)
$ git remote add RemoteTech-Common https://github.com/RemoteTechnologiesGroup/RemoteTech-Common.git

Next add the subtree to RemoteTech-Complete. The command is:

$ git subtree add --prefix=<location> <friendly_name> <branch> --squash

Where:

  • <location> is the location of the subtree inside RemoteTech-Common
  • <friendly_name> is the name of the repository used in the previous step
  • <branch> is the branch from which to get the code
  • --squash: Always use this option to avoid polluting the history of the repository containing the subtree(s)

Example:

Neitsa@Falcon /RemoteTech-Complete (develop)
$ git subtree add --prefix=src/RemoteTech-Common RemoteTech-Common develop --squash
git fetch RemoteTech-Common develop
From https://github.com/RemoteTechnologiesGroup/RemoteTech-Common
* branch            develop    -> FETCH_HEAD
Added dir 'src/RemoteTech-Common'

Note: If you have a problem while trying to add a new subtree:

Neitsa@Falcon RemoteTech/RemoteTech-Complete (develop)
$ git subtree add --prefix=src/RemoteTech-CommandHandler RemoteTech-CommandHandler develop --squash
Working tree has modifications.  Cannot add.
  1. Check the output of git status in case you have untracked files or files waiting to be committed.
  2. If the output of git status indicates a clean working directory state, try git diff-index HEAD.
  3. Takes proper action if the above command (git diff-index HEAD) indicates a non clean working directory.
  4. If both git status and git diff-index HEAD doesn't output something that needs immediate action, consider re-checking out the branch you are on:
    • git checkout <branch>

Updating a subtree

If you need to update the subtree in RemoteTech-Complete, use the subtree pull command:

Neitsa@Falcon /RemoteTech-Complete (develop)
$ git subtree pull --prefix=<location> <friendly_name> <branch> --squash

Example:

Neitsa@Falcon /RemoteTech-Complete (develop)
$ git subtree pull --prefix=src/RemoteTech-Common RemoteTech-Common develop --squash

Updating the subtrees of the RemoteTech-Completerepository can be done with the scripts/update_subtrees.sh script in this repo (see here).

Checking the update was correct

You must check and ensure that the merging strategy made by git subtree pull ... is correct. Sometimes it can go awry for no apparent reason.

Example: while trying to update RemoteTech-Delay into RemoteTech-Complete the merge did remove a lot of files that were absolutely not related to the subtree:

Removing src/RemoteTech-Transmitter/src/RemoteTech-Transmitter/RemoteTech-Transmitter.csproj
Removing src/RemoteTech-Transmitter/src/RemoteTech-Transmitter/Properties/AssemblyInfo.cs
Removing src/RemoteTech-Transmitter/src/RemoteTech-Transmitter/ModuleRTDeployableAntenna.cs
Removing src/RemoteTech-Transmitter/src/RemoteTech-Transmitter/ModuleRTDataTransmitter.cs
Removing src/RemoteTech-Transmitter/README.md
Removing src/RemoteTech-Transmitter/LICENSE
Removing src/RemoteTech-Transmitter/.gitignore
Removing src/RemoteTech-Transmitter/.gitattributes
Removing src/RemoteTech-Delay/src/RemoteTech-Delay/RemoteTechDelayCore.cs
... [the merge removed 260 files]

If this goes wrong,first get your tree:

Neitsa@Falcon RemoteTech/RemoteTech-Complete (develop)
$ git log --oneline --graph --decorate
*   f2a4b44 (HEAD -> develop) Merge commit 'aac33a23628e3f7ade006bcc89f5beddd292fa86' into develop
|\
| * aac33a2 Squashed 'src/RemoteTech-Delay/' changes from a2494cb..2057229
* |   abe70c7 (origin/develop) Merge commit 'c911056003aada98a83b5d8659abe258d78528b0' into develop
|\ \
| * | c911056 Squashed 'src/RemoteTech-Transmitter/' changes from 98cdd5e..1bf57af
* | |   9ff2128 Merge commit '38d1b3f33d5d9b7aa9b3a5e80db7b482591d82ca' into develop
|\ \ \
| * | | 38d1b3f Squashed 'src/RemoteTech-Common/' changes from 40966cf..9525a6e
* | | | a2f730c Update script for subtree updating: Add RT-CommandHandler.
* | | |   5caa838 Merge commit 'aa10d57c50d9c6b463242f53e9f65fbdda283bbd' as 'src/RemoteTech-CommandHandler'

Here, commit abe70c7 is the last known good commit that was made before everything was foobar.

Knowing the last good commit, reset to the previous working merge / commit:

Neitsa@Falcon RemoteTech/RemoteTech-Complete (develop)
$ git reset --hard abe70c7fbf214a5bb20e4cbb44e129269887cc80 --

Now you'll need to to the merge by hand instead of using the git subtree pull command:

Clone this wiki locally