xref: /openbmc/docs/subtree.md (revision c7c7c866)
1# Subtree Architecture
2
3All of these directories are subtrees and may not be contributed to by pushing
4directly to the openbmc/openbmc top level repository
5
6Subtrees are a way to nest repositories inside another as a sub-directory. This
7allows us to contain all of the Yocto meta-data in individual repositories
8(useful for developers who don't want the phosphor-distro), as well as one top
9level directory - making it easy to get started.
10
11To find a list of all current subtrees in the openbmc project, navigate to:
12https://github.com/openbmc?utf8=✓&q=meta
13
14Instead, please follow this workflow:
15```
16$ git clone https://gerrit.openbmc-project.xyz/openbmc/openbmc
17# Make changes
18$ bitbake obmc-phosphor-image # Test out your changes
19$ git commit
20$ git remote add <repo_name> ssh://openbmc.gerrit/openbmc/<repo_name>/
21$ git fetch <repo_name>
22$ git checkout -b featureBranch <repo_name>/master
23$ git cherry-pick --strategy=subtree <SHA> # My commit from master
24$ git push ssh://openbmc.gerrit/openbmc/<repo_name> HEAD:refs/for/master
25
26$ git checkout master # To continue work on something unrelated
27```
28
29If you have lost the commit from the parent repo and need to do work on your
30subtree code review:
31```
32$ git checkout featureBranch
33$ git log -n1 --oneline # capture the SHA
34$ git checkout master
35$ git cherry-pick --strategy=subtree <SHA you just captured>
36```
37
38If for some reason you have lost the featureBranch:
39```
40$ git checkout -b featureBranch
41$ git fetch ssh://openbmc.gerrit/openbmc/<repo_name> refs/changes/XX/XXXX/X
42$ git checkout FETCH_HEAD
43$ git log -n1 --oneline # Capture the SHA
44$ git checkout master
45$ git cherry-pick --strategy=subtree <SHA you just captured>
46```
47
48### Automation to test the ref
49Where $1 is the repo name, and $2 is a ref to a pointer
50```
51git clone https://gerrit.openbmc-project.xyz/openbmc/openbmc
52cd openbmc
53git remote add subtree-remote https://gerrit.openbmc-project.xyz/openbmc/$1
54git fetch ssh://openbmc.gerrit/openbmc/$1 refs/changes/$2
55git cherry-pick --strategy=subtree FETCH_HEAD
56```
57
58### Automation to merge the subtree into openbmc/openbmc
59Once +2 is given, this script will run where $1 is the repo name, and $2 is a
60full path to subtree from top level
61```
62git clone ssh://<user>@gerrit.openbmc-project.xyz:29418/openbmc/openbmc
63cd openbmc
64git remote add subtree-remote https://gerrit.openbmc-project.xyz/openbmc/$1
65
66git subtree pull --prefix=$2 subtree-remote master
67git push
68```
69
70To keep yourself up to date with the latest as changes are submitted, you can
71simply rebase again the openbmc master, and you will automatically get the
72changes made in the sub-directories.
73```
74git checkout master
75git pull --rebase origin master
76```
77