@@ -8,6 +8,166 @@ in the [GoogleCloudPlaftorm](https://github.com/GoogleCloudPlatform)
8
8
organization.
9
9
10
10
11
+ ## Using this repository
12
+
13
+ This repository is copied into a subtree of other Java repositories, such as
14
+ [ java-docs-samples] ( /GoogleCloudPlatform/java-docs-samples ) . Note, that a
15
+ subtree is just the code copied into a directory, so a regular ` git clone ` will
16
+ continue to work.
17
+
18
+
19
+ ### Adding to a new repository
20
+
21
+ To copy ` java-repo-tools ` into a subtree of a new repository ` my-java-samples ` ,
22
+ first add this repository as a remote. We then fetch all the changes from this
23
+ ` java-repo-tools ` .
24
+
25
+ ```
26
+ git remote add java-repo-tools [email protected] :GoogleCloudPlatform/java-repo-tools.git
27
+ git fetch java-repo-tools master
28
+ ```
29
+
30
+ To make it easier to push changes back upstream, create a new branch.
31
+
32
+ ```
33
+ git checkout -b java-repo-tools java-repo-tools/master
34
+ ```
35
+
36
+ We can then go back to the ` my-java-samples ` code and prepare a Pull Request to
37
+ add the ` java-repo-tools ` code in a subtree.
38
+
39
+ ```
40
+ git checkout master
41
+ # Making a new branch ia optional, but recommended to send a pull request to
42
+ # start using java-repo-tools.
43
+ git checkout -b use-java-repo-tools
44
+ ```
45
+
46
+ So that we can pull future updates from the ` java-repo-tools ` repository, we
47
+ merge histories. This way we won't get unnecessary conflicts when pulling changes
48
+ in.
49
+
50
+ ```
51
+ git merge -s ours --no-commit java-repo-tools/master
52
+ ```
53
+
54
+ Finally, read the ` java-repo-tools ` into a subtree.
55
+
56
+ ```
57
+ git read-tree --prefix=java-repo-tools/ -u java-repo-tools
58
+ ```
59
+
60
+ Now all the content of ` java-repo-tools ` will be in the ` java-repo-tools/ `
61
+ directory (which we specified in the ` --prefix ` command).
62
+
63
+ #### Using the Maven configuration
64
+
65
+ If all the projects within your ` my-java-samples ` share a common parent POM for
66
+ plugin configuration (like checkstyle). We can then make the
67
+ ` java-repo-tools/pom.xml ` parent of this.
68
+
69
+ ```
70
+ <!-- Parent POM defines common plugins and properties. -->
71
+ <parent>
72
+ <groupId>com.google.cloud</groupId>
73
+ <artifactId>shared-configuration</artifactId>
74
+ <version>1.0.0</version>
75
+ <relativePath>java-repo-tools</relativePath>
76
+ </parent>
77
+ ```
78
+
79
+ Once this is added to the common parent, all modules will have the same plugin
80
+ configuration applied. If the children POMs provide the plugin information
81
+ themselves, it will override this configuration, so you should delete any
82
+ now-redundant plugin information.
83
+
84
+
85
+ #### Examples
86
+
87
+ - Adding to repository with an existing parent POM: Pull Request
88
+ [ java-docs-samples #125 ] [ java-docs-samples-125 ] .
89
+
90
+ [ java-docs-samples-125 ] : https://github.com/GoogleCloudPlatform/java-docs-samples/pull/125
91
+
92
+
93
+ ### Detecting if you need to synchronize a subtree
94
+
95
+ If you haven't done this before, run
96
+
97
+ ```
98
+ git remote add java-repo-tools [email protected] :GoogleCloudPlatform/java-repo-tools.git
99
+ ```
100
+
101
+ To detect if you have changes in the directory, run
102
+
103
+ ```
104
+ git fetch java-repo-tools master
105
+ git diff-tree -p HEAD:java-repo-tools/ java-repo-tools/master
106
+ ```
107
+
108
+ or to diff against your local ` java-repo-tools ` branch:
109
+
110
+ ```
111
+ git diff-tree -p HEAD:java-repo-tools/ java-repo-tools --
112
+ ```
113
+
114
+ (The trailing ` -- ` is to say that we want to compare against the branch, not the
115
+ directory.)
116
+
117
+
118
+ ### Pulling changes from Java Repository Tools to a subtree
119
+
120
+ To update the ` java-repo-tools ` directory, if you haven't done this before, run
121
+
122
+ ```
123
+ git remote add java-repo-tools [email protected] :GoogleCloudPlatform/java-repo-tools.git
124
+ ```
125
+
126
+ To pull the latest changes from this ` java-repo-tools ` repository, run:
127
+
128
+ ```
129
+ git checkout master
130
+ # Making a new branch is optional, but recommended to send a pull request for
131
+ # update.
132
+ git checkout -b update-java-repo-tools
133
+ git pull -s subtree java-repo-tools master
134
+ ```
135
+
136
+ Then you can make any needed changes to make the rest of the repository
137
+ compatible with the updated ` java-repo-tools ` code, commit, push, and send a
138
+ Pull Request as you would in the normal flow.
139
+
140
+
141
+ ### Pushing changes from a subtree upstream to Java Repository Tools
142
+
143
+ What if you make changes in your repository and now want to push them upstream?
144
+
145
+ Assuming you just commited changes in the ` java-repo-tools/ ` directory of your
146
+ ` my-main-branch ` , to merge the changes into the local ` java-repo-tools ` branch,
147
+ we need to cherry pick this commit using the subtree strategy. It will ignore
148
+ any changes to file not in the ` java-repo-tools/ ` directory.
149
+
150
+ ```
151
+ git checkout java-repo-tools
152
+ git cherry-pick -x --strategy=subtree my-main-branch
153
+ ```
154
+
155
+ After you have committed all the changes you want to your ` java-repo-tools `
156
+ branch, you can push to the upstream ` java-repo-tools ` repository with the
157
+ following command. (Replace ` name-for-remote-branch ` with the name you'd like to
158
+ give the branch on the ` java-repo-tools ` repository.)
159
+
160
+ ```
161
+ git push java-repo-tools java-repo-tools:name-for-remote-branch
162
+ ```
163
+
164
+ Then, you can send a pull request to the ` java-repo-tools ` repository.
165
+
166
+
167
+ ## References
168
+
169
+ - [ GitHub's subtree merge reference] ( https://help.github.com/articles/about-git-subtree-merges/ )
170
+
11
171
## Contributing changes
12
172
13
173
- See [ CONTRIBUTING.md] ( CONTRIBUTING.md )
0 commit comments