Skip to content

Commit 1b06cbf

Browse files
committed
Add --file option
Allow the commit to be passed in as a file. Also added the option of modifying the commit message for the push command. Change-Id: Id8e245a80ad46d2a303b0e18739e40f4ba6f3f45
1 parent b4ae8f1 commit 1b06cbf

File tree

5 files changed

+130
-94
lines changed

5 files changed

+130
-94
lines changed

ReadMe.pod

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ all the same arguments. Keep reading…
128128

129129
=over
130130

131-
=item C<< git subrepo clone <repository> [<subdir>] [-b <branch>] [-f] [-m <msg>] [-e] [--method <merge|rebase>] >>
131+
=item C<< git subrepo clone <repository> [<subdir>] [-b <branch>] [-f] [-m <msg>] [--file=<msg file>] [-e] [--method <merge|rebase>] >>
132132

133133
Add a repository as a subrepo in a subdir of your repository.
134134

@@ -150,8 +150,8 @@ The C<--force> option will "reclone" (completely replace) an existing subdir.
150150
The C<--method> option will decide how the join process between branches are
151151
performed. The default option is merge.
152152

153-
The C<clone> command accepts the C<--branch=> C<--edit>, C<--force> and C<--
154-
message=> options.
153+
The C<clone> command accepts the C<--branch=> C<--edit>, C<--file>, C<--force>
154+
and C<--message=> options.
155155

156156
=item C<< git subrepo init <subdir> [-r <remote>] [-b <branch>] [--method <merge|rebase>] >>
157157

@@ -160,15 +160,13 @@ Turn an existing subdirectory into a subrepo.
160160
If you want to expose a subdirectory of your project as a published subrepo,
161161
this command will do that. It will split out the content of a normal
162162
subdirectory into a branch and start tracking it as a subrepo. Afterwards your
163-
original repo will look exactly the same except that there will be a C<<
164-
<subdir>/.gitrepo >> file.
163+
original repo will look exactly the same except that there will be a C<<<subdir>/.gitrepo >> file.
165164

166165
If you specify the C<--remote> (and optionally the C<--branch>) option, the
167166
values will be added to the C<< <subdir>/.gitrepo >> file. The C<--remote>
168167
option is the upstream URL, and the C<--branch> option is the upstream branch
169168
to push to. These values will be needed to do a C<git subrepo push> command,
170-
but they can be provided later on the C<push> command (and saved to C<<
171-
<subdir>/.gitrepo >> if you also specify the C<--update> option).
169+
but they can be provided later on the C<push> command (and saved to C<<<subdir>/.gitrepo >> if you also specify the C<--update> option).
172170

173171
Note: You will need to create the empty upstream repo and push to it on your
174172
own, using C<< git subrepo push <subdir> >>.
@@ -178,7 +176,7 @@ performed. The default option is merge.
178176

179177
The C<init> command accepts the C<--branch=> and C<--remote=> options.
180178

181-
=item C<< git subrepo pull <subdir>|--all [-M|-R|-f] [-m <msg>] [-e] [-b <branch>] [-r <remote>] [-u] >>
179+
=item C<< git subrepo pull <subdir>|--all [-M|-R|-f] [-m <msg>] [--file=<msg file>] [-e] [-b <branch>] [-r <remote>] [-u] >>
182180

183181
Update the subrepo subdir with the latest upstream changes.
184182

@@ -223,10 +221,10 @@ clean. You can easily see the subrepo's history with the C<git log> command:
223221

224222
The set of commands used above are described in detail below.
225223

226-
The C<pull> command accepts the C<--all>, C<--branch=>, C<--edit>, C<--force>,
227-
C<--message=>, C<--remote=> and C<--update> options.
224+
The C<pull> command accepts the C<--all>, C<--branch=>, C<--edit>, C<--file>,
225+
C<--force>, C<--message=>, C<--remote=> and C<--update> options.
228226

229-
=item C<< git subrepo push <subdir>|--all [<branch>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N] >>
227+
=item C<< git subrepo push <subdir>|--all [<branch>] [-m msg] [--file=<msg file>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N] >>
230228

231229
Push a properly merged subrepo branch back upstream.
232230

@@ -250,9 +248,7 @@ The C<--force> option will do a force push. Force pushes are typically
250248
discouraged. Only use this option if you fully understand it. (The C<--force>
251249
option will NOT check for a proper merge. ANY branch will be force pushed!)
252250

253-
The C<push> command accepts the C<--all>, C<--branch=>, C<--dry-run>, C<--
254-
force>, C<--merge>, C<--rebase>, C<--remote=>, C<--squash> and C<--
255-
update> options.
251+
The C<push> command accepts the C<--all>, C<--branch=>, C<--dry-run>, C<--file>, C<--force>, C<--merge>, C<--message>, C<--rebase>, C<--remote=>, C<--squash> and C<--update> options.
256252

257253
=item C<< git subrepo fetch <subdir>|--all [-r <remote>] [-b <branch>] >>
258254

@@ -263,8 +259,7 @@ points at the same commit as C<FETCH_HEAD>. It will also create a remote
263259
called C<< subrepo/<subdir> >>. These are temporary and you can easily remove
264260
them with the subrepo C<clean> command.
265261

266-
The C<fetch> command accepts the C<--all>, C<--branch=> and C<--
267-
remote=> options.
262+
The C<fetch> command accepts the C<--all>, C<--branch=> and C<--remote=> options.
268263

269264
=item C<< git subrepo branch <subdir>|--all [-f] [-F] >>
270265

@@ -280,26 +275,24 @@ Use the C<--force> option to write over an existing C<< subrepo/<subdir>
280275

281276
The C<branch> command accepts the C<--all>, C<--fetch> and C<--force> options.
282277

283-
=item C<< git subrepo commit <subdir> [<subrepo-ref>] [-m <msg>] [-e] [-f] [-F] >>
278+
=item C<< git subrepo commit <subdir> [<subrepo-ref>] [-m <msg>] [--file=<msg file>] [-e] [-f] [-F] >>
284279

285280
Add subrepo branch to current history as a single commit.
286281

287-
This command is generally used after a hand-merge. You have done a C<subrepo
288-
branch> and merged (rebased) it with the upstream. This command takes the HEAD
282+
This command is generally used after a hand-merge. You have done a C<subrepobranch> and merged (rebased) it with the upstream. This command takes the HEAD
289283
of that branch, puts its content into the subrepo subdir and adds a new commit
290284
for it to the top of your mainline history.
291285

292286
This command requires that the upstream HEAD be in the C<< subrepo/<subdir> >>
293287
branch history. That way the same branch can push upstream. Use the C<--force>
294288
option to commit anyway.
295289

296-
The C<commit> command accepts the C<--edit>, C<--fetch>, C<--force> and C<--
297-
message=> options.
290+
The C<commit> command accepts the C<--edit>, C<--fetch>, C<--file>, C<--force>
291+
and C<--message=> options.
298292

299293
=item C<< git subrepo status [<subdir>|--all|--ALL] [-F] [-q|-v] >>
300294

301-
Get the status of a subrepo. Uses the C<--all> option by default. If the C<--
302-
quiet> flag is used, just print the subrepo names, one per line.
295+
Get the status of a subrepo. Uses the C<--all> option by default. If the C<--quiet> flag is used, just print the subrepo names, one per line.
303296

304297
The C<--verbose> option will show all the recent local and upstream commits.
305298

@@ -416,6 +409,10 @@ Edit the commit message before committing.
416409

417410
Use this option to fetch the upstream commits, before running the command.
418411

412+
=item C<< --file=<commit msg file> >>
413+
414+
Supply your own commit message from a file
415+
419416
=item C<--force> (C<-f>)
420417

421418
Use this option to force certain commands that fail in the general case.
@@ -486,8 +483,7 @@ The C<git-subrepo> command exports and honors some environment variables:
486483

487484
=item C<GIT_SUBREPO_ROOT>
488485

489-
This is set by the C<.rc> file, if you use that method to install / enable C<git-
490-
subrepo>. It contains the path of the C<git-subrepo> repository.
486+
This is set by the C<.rc> file, if you use that method to install / enable C<git-subrepo>. It contains the path of the C<git-subrepo> repository.
491487

492488
=item C<GIT_SUBREPO_RUNNING>
493489

doc/git-subrepo.swim

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ experienced Git users.
8888
Please note that the commands are /not/ exact equivalents, and do not take all
8989
the same arguments. Keep reading…
9090

91-
- `git subrepo clone <repository> [<subdir>] [-b <branch>] [-f] [-m <msg>] [-e] [--method <merge|rebase>]`
91+
- `git subrepo clone <repository> [<subdir>] [-b <branch>] [-f] [-m <msg>] [--file=<msg file>] [-e] [--method <merge|rebase>]`
9292

9393
Add a repository as a subrepo in a subdir of your repository.
9494

@@ -110,8 +110,8 @@ the same arguments. Keep reading…
110110
The `--method` option will decide how the join process between branches are
111111
performed. The default option is merge.
112112

113-
The `clone` command accepts the `--branch=` `--edit`, `--force` and
114-
`--message=` options.
113+
The `clone` command accepts the `--branch=` `--edit`, `--file`, `--force`
114+
and `--message=` options.
115115

116116
- `git subrepo init <subdir> [-r <remote>] [-b <branch>] [--method <merge|rebase>]`
117117

@@ -126,7 +126,7 @@ the same arguments. Keep reading…
126126
If you specify the `--remote` (and optionally the `--branch`) option, the
127127
values will be added to the `<subdir>/.gitrepo` file. The `--remote` option
128128
is the upstream URL, and the `--branch` option is the upstream branch to push
129-
to. These values will be needed to do a `git subrepo push` command, but they
129+
to. These values will be needed to do a `git subrepo push` command, but they
130130
can be provided later on the `push` command (and saved to `<subdir>/.gitrepo`
131131
if you also specify the `--update` option).
132132

@@ -138,7 +138,7 @@ the same arguments. Keep reading…
138138

139139
The `init` command accepts the `--branch=` and `--remote=` options.
140140

141-
- `git subrepo pull <subdir>|--all [-M|-R|-f] [-m <msg>] [-e] [-b <branch>] [-r <remote>] [-u]`
141+
- `git subrepo pull <subdir>|--all [-M|-R|-f] [-m <msg>] [--file=<msg file>] [-e] [-b <branch>] [-r <remote>] [-u]`
142142

143143
Update the subrepo subdir with the latest upstream changes.
144144

@@ -183,10 +183,10 @@ the same arguments. Keep reading…
183183

184184
The set of commands used above are described in detail below.
185185

186-
The `pull` command accepts the `--all`, `--branch=`, `--edit`, `--force`,
187-
`--message=`, `--remote=` and `--update` options.
186+
The `pull` command accepts the `--all`, `--branch=`, `--edit`, `--file`,
187+
`--force`, `--message=`, `--remote=` and `--update` options.
188188

189-
- `git subrepo push <subdir>|--all [<branch>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N]`
189+
- `git subrepo push <subdir>|--all [<branch>] [-m msg] [--file=<msg file>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N]`
190190

191191
Push a properly merged subrepo branch back upstream.
192192

@@ -210,8 +210,9 @@ the same arguments. Keep reading…
210210
discouraged. Only use this option if you fully understand it. (The `--force`
211211
option will NOT check for a proper merge. ANY branch will be force pushed!)
212212

213-
The `push` command accepts the `--all`, `--branch=`, `--dry-run`, `--force`,
214-
`--merge`, `--rebase`, `--remote=`, `--squash` and `--update` options.
213+
The `push` command accepts the `--all`, `--branch=`, `--dry-run`, `--file`,
214+
`--force`, `--merge`, `--message`, `--rebase`, `--remote=`, `--squash` and
215+
`--update` options.
215216

216217
- `git subrepo fetch <subdir>|--all [-r <remote>] [-b <branch>]`
217218

@@ -237,7 +238,7 @@ the same arguments. Keep reading…
237238

238239
The `branch` command accepts the `--all`, `--fetch` and `--force` options.
239240

240-
- `git subrepo commit <subdir> [<subrepo-ref>] [-m <msg>] [-e] [-f] [-F]`
241+
- `git subrepo commit <subdir> [<subrepo-ref>] [-m <msg>] [--file=<msg file>] [-e] [-f] [-F]`
241242

242243
Add subrepo branch to current history as a single commit.
243244

@@ -250,8 +251,8 @@ the same arguments. Keep reading…
250251
branch history. That way the same branch can push upstream. Use the
251252
`--force` option to commit anyway.
252253

253-
The `commit` command accepts the `--edit`, `--fetch`, `--force` and
254-
`--message=` options.
254+
The `commit` command accepts the `--edit`, `--fetch`, `--file`, `--force`
255+
and `--message=` options.
255256

256257
- `git subrepo status [<subdir>|--all|--ALL] [-F] [-q|-v]`
257258

@@ -368,6 +369,10 @@ the same arguments. Keep reading…
368369

369370
Use this option to fetch the upstream commits, before running the command.
370371

372+
- `--file=<commit msg file>`
373+
374+
Supply your own commit message from a file
375+
371376
- `--force` (`-f`)
372377

373378
Use this option to force certain commands that fail in the general case.

lib/git-subrepo

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ f,force Force certain operations
7373
F,fetch Fetch the upstream content first
7474
M,method= Join method: 'merge' (default) or 'rebase'
7575
m,message= Specify a commit message
76+
file= Specify a commit message file
7677
r,remote= Specify the upstream remote to push/pull/fetch
7778
s,squash Squash commits on push
7879
u,update Add the --branch and/or --remote overrides to .gitrepo
@@ -131,6 +132,7 @@ main() {
131132

132133
local edit_wanted=false # Edit commit message using -e
133134
local wanted_commit_message= # Custom commit message using -m
135+
local commit_msg_file= # Custom commit message using --file
134136

135137
local join_method= # Current join method (rebase/merge)
136138

@@ -685,7 +687,19 @@ subrepo:push() {
685687
upstream_head_commit=$new_upstream_head_commit
686688
subrepo_commit_ref=$upstream_head_commit
687689
update-gitrepo-file
688-
RUN git commit -m "$(get-commit-message)"
690+
691+
local commit_message
692+
if [[ $wanted_commit_message ]]; then
693+
commit_message=$wanted_commit_message
694+
else
695+
commit_message=$(get-commit-message)
696+
fi
697+
698+
if [[ $commit_msg_file ]]; then
699+
RUN git command --file "$commit_msg_file"
700+
else
701+
RUN git commit -m "$commit_message"
702+
fi
689703
}
690704

691705
# Fetch the subrepo's remote branch content:
@@ -872,13 +886,21 @@ subrepo:commit() {
872886

873887
o "Commit to the '$original_head_branch' branch."
874888
if [[ $original_head_commit != none ]]; then
875-
RUN git commit $edit_flag -m "$commit_message"
889+
if [[ $commit_msg_file ]]; then
890+
RUN git commit $edit_flag --file "$commit_msg_file"
891+
else
892+
RUN git commit $edit_flag -m "$commit_message"
893+
fi
876894
else
877895
# We had cloned into an empty repo, side effect of prior git reset --mixed
878896
# command is that subrepo's history is now part of the index. Commit
879897
# without that history.
880898
OUT=true RUN git write-tree
881-
OUT=true RUN git commit-tree $edit_flag -m "$commit_message" "$output"
899+
if [[ $commit_msg_file ]]; then
900+
OUT=true RUN git commit-tree $edit_flag --file "$commit_msg_file" "$output"
901+
else
902+
OUT=true RUN git commit-tree $edit_flag -m "$commit_message" "$output"
903+
fi
882904
RUN git reset --hard "$output"
883905
fi
884906

@@ -1039,7 +1061,11 @@ get-command-options() {
10391061
-f) force_wanted=true
10401062
commit_msg_args+=("--force") ;;
10411063
-F) fetch_wanted=true ;;
1042-
-m) wanted_commit_message=$1
1064+
-m)
1065+
if [[ $commit_msg_file ]]; then
1066+
error "fatal: options '-m' and '--file' cannot be used together"
1067+
fi
1068+
wanted_commit_message=$1
10431069
shift;;
10441070
-M) join_method=$1
10451071
shift;;
@@ -1054,6 +1080,16 @@ get-command-options() {
10541080
-v) verbose_wanted=true ;;
10551081
-d) debug_wanted=true ;;
10561082
-x) set -x ;;
1083+
--file)
1084+
if [[ $wanted_commit_message ]]; then
1085+
error "fatal: options '-m' and '--file' cannot be used together"
1086+
fi
1087+
if [ -f "$1" ]; then
1088+
commit_msg_file="$1"
1089+
else
1090+
error "Commit msg file at $1 not found"
1091+
fi
1092+
shift ;;
10571093
--version)
10581094
echo "$VERSION"
10591095
exit ;;
@@ -1089,7 +1125,7 @@ get-command-options() {
10891125
if [[ $override_remote ]]; then
10901126
check_option remote
10911127
fi
1092-
if [[ $wanted_commit_message ]]; then
1128+
if [[ $wanted_commit_message || $commit_msg_file ]]; then
10931129
check_option message
10941130
fi
10951131
if $update_wanted; then
@@ -1109,7 +1145,7 @@ options_commit='edit fetch force message'
11091145
options_fetch='all branch remote'
11101146
options_init='branch remote method'
11111147
options_pull='all branch edit force message remote update'
1112-
options_push='all branch force remote squash update'
1148+
options_push='all branch force message remote squash update'
11131149
options_status='ALL all fetch'
11141150
check_option() {
11151151
local var=options_${command//-/_}

0 commit comments

Comments
 (0)