@@ -8,6 +8,161 @@ 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
+ git read-tree --prefix=java-repo-tools/ -u java-repo-tools
45
+ ```
46
+
47
+ Now all the content of ` java-repo-tools ` will be in the ` java-repo-tools/ `
48
+ directory (which we specified in the ` --prefix ` command).
49
+
50
+ #### Using the Maven configuration
51
+
52
+ If all the projects within your ` my-java-samples ` share a common parent POM for
53
+ plugin configuration (like checkstyle). We can then make the
54
+ ` java-repo-tools/pom.xml ` parent of this.
55
+
56
+ ```
57
+ <!-- Parent POM defines common plugins and properties. -->
58
+ <parent>
59
+ <groupId>com.google.cloud</groupId>
60
+ <artifactId>shared-configuration</artifactId>
61
+ <version>1.0.0</version>
62
+ <relativePath>java-repo-tools</relativePath>
63
+ </parent>
64
+ ```
65
+
66
+ Once this is added to the common parent, all modules will have the same plugin
67
+ configuration applied. If the children POMs provide the plugin information
68
+ themselves, it will override this configuration, so you should delete any
69
+ now-redundant plugin information.
70
+
71
+
72
+ #### Examples
73
+
74
+ - Adding to repository with an existing parent POM: Pull Request
75
+ [ java-docs-samples #125 ] [ java-docs-samples-125 ] .
76
+
77
+ [ java-docs-samples-125 ] : https://github.com/GoogleCloudPlatform/java-docs-samples/pull/125
78
+
79
+
80
+ ### Detecting if you need to synchronize a subtree
81
+
82
+ If you haven't done this before, run
83
+
84
+ ```
85
+ git remote add java-repo-tools [email protected] :GoogleCloudPlatform/java-repo-tools.git
86
+ git fetch java-repo-tools master
87
+ # Optional, but it makes pushing changes upstream easier.
88
+ git checkout -b java-repo-tools java-repo-tools/master
89
+ ```
90
+
91
+ To detect if you have changes in the directory, run
92
+
93
+ ```
94
+ git fetch java-repo-tools
95
+ git diff-tree -p HEAD:java-repo-tools/ java-repo-tools/master
96
+ ```
97
+
98
+ or to diff against your local ` java-repo-tools ` branch:
99
+
100
+ ```
101
+ git diff-tree -p HEAD:java-repo-tools/ java-repo-tools --
102
+ ```
103
+
104
+ (The trailing ` -- ` is to say that we want to compare against the branch, not the
105
+ directory.)
106
+
107
+
108
+ ### Pulling changes from Java Repository Tools to a subtree
109
+
110
+ To update the ` java-repo-tools ` directory, if you haven't done this before, run
111
+
112
+ ```
113
+ git remote add java-repo-tools [email protected] :GoogleCloudPlatform/java-repo-tools.git
114
+ git fetch java-repo-tools master
115
+ git checkout -b java-repo-tools java-repo-tools/master
116
+ ```
117
+
118
+ To pull the latest changes from this ` java-repo-tools ` repository, run:
119
+
120
+ ```
121
+ git checkout java-repo-tools
122
+ git pull java-repo-tools master
123
+ ```
124
+
125
+ Pull them into the main code.
126
+
127
+ ```
128
+ git checkout master
129
+ # Making a new branch is optional, but recommended to send a pull request for
130
+ # update.
131
+ git checkout -b update-java-repo-tools
132
+ git merge --squash -Xsubtree=java-repo-tools/ --no-commit java-repo-tools
133
+ ```
134
+
135
+ Then you can make any needed changes to make the rest of the repository
136
+ compatible with the updated ` java-repo-tools ` code, commit, push, and send a
137
+ Pull Request as you would in the normal flow.
138
+
139
+
140
+ ### Pushing changes from a subtree upstream to Java Repository Tools
141
+
142
+ What if you make changes in your repository and now want to push them upstream?
143
+
144
+ Assuming you just commited changes in the ` java-repo-tools/ ` directory of your
145
+ ` my-main-branch ` , to merge the changes into the local ` java-repo-tools ` branch,
146
+ we need to cherry pick this commit using the subtree strategy. It will ignore
147
+ any changes to file not in the ` java-repo-tools/ ` directory.
148
+
149
+ ```
150
+ git checkout java-repo-tools
151
+ git cherry-pick -x --strategy=subtree my-main-branch
152
+ ```
153
+
154
+ After you have committed all the changes you want to your ` java-repo-tools `
155
+ branch, you can push to the upstream ` java-repo-tools ` repository with the
156
+ following command. (Replace ` name-for-remote-branch ` with the name you'd like to
157
+ give the branch on the ` java-repo-tools ` repository.)
158
+
159
+ ```
160
+ git push java-repo-tools java-repo-tools:name-for-remote-branch
161
+ ```
162
+
163
+ Then, you can send a pull request to the ` java-repo-tools ` repository.
164
+
165
+
11
166
## Contributing changes
12
167
13
168
- See [ CONTRIBUTING.md] ( CONTRIBUTING.md )
0 commit comments