Skip to content

Commit f55b87c

Browse files
merloromgitster
authored andcommitted
git-p4: add options --commit and --disable-rebase
On a daily work with multiple local git branches, the usual way to submit only a specified commit was to cherry-pick the commit on master then run git-p4 submit. It can be very annoying to switch between local branches and master, only to submit one commit. The proposed new way is to select directly the commit you want to submit. Add option --commit to command 'git-p4 submit' in order to submit only specified commit(s) in p4. On a daily work developping software with big compilation time, one may not want to rebase on his local git tree, in order to avoid long recompilation. Add option --disable-rebase to command 'git-p4 submit' in order to disable rebase after submission. Thanks-to: Cedric Borgese <[email protected]> Reviewed-by: Luke Diamand <[email protected]> Signed-off-by: Romain Merland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccdcbd5 commit f55b87c

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

Documentation/git-p4.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ To specify a branch other than the current one, use:
149149
$ git p4 submit topicbranch
150150
------------
151151

152+
To specify a single commit or a range of commits, use:
153+
------------
154+
$ git p4 submit --commit <sha1>
155+
$ git p4 submit --commit <sha1..sha1>
156+
------------
157+
152158
The upstream reference is generally 'refs/remotes/p4/master', but can
153159
be overridden using the `--origin=` command-line option.
154160

@@ -330,6 +336,14 @@ These options can be used to modify 'git p4 submit' behavior.
330336
p4/master. See the "Sync options" section above for more
331337
information.
332338

339+
--commit <sha1>|<sha1..sha1>::
340+
Submit only the specified commit or range of commits, instead of the full
341+
list of changes that are in the current Git branch.
342+
343+
--disable-rebase::
344+
Disable the automatic rebase after all commits have been successfully
345+
submitted.
346+
333347
Rebase options
334348
~~~~~~~~~~~~~~
335349
These options can be used to modify 'git p4 rebase' behavior.

git-p4.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,12 @@ def __init__(self):
13521352
optparse.make_option("--update-shelve", dest="update_shelve", action="append", type="int",
13531353
metavar="CHANGELIST",
13541354
help="update an existing shelved changelist, implies --shelve, "
1355-
"repeat in-order for multiple shelved changelists")
1355+
"repeat in-order for multiple shelved changelists"),
1356+
optparse.make_option("--commit", dest="commit", metavar="COMMIT",
1357+
help="submit only the specified commit(s), one commit or xxx..xxx"),
1358+
optparse.make_option("--disable-rebase", dest="disable_rebase", action="store_true",
1359+
help="Disable rebase after submit is completed. Can be useful if you "
1360+
"work from a local git branch that is not master")
13561361
]
13571362
self.description = "Submit changes from git to the perforce depot."
13581363
self.usage += " [name of git branch to submit into perforce depot]"
@@ -1362,6 +1367,8 @@ def __init__(self):
13621367
self.dry_run = False
13631368
self.shelve = False
13641369
self.update_shelve = list()
1370+
self.commit = ""
1371+
self.disable_rebase = False
13651372
self.prepare_p4_only = False
13661373
self.conflict_behavior = None
13671374
self.isWindows = (platform.system() == "Windows")
@@ -2103,9 +2110,18 @@ def run(self, args):
21032110
else:
21042111
commitish = 'HEAD'
21052112

2106-
for line in read_pipe_lines(["git", "rev-list", "--no-merges", "%s..%s" % (self.origin, commitish)]):
2107-
commits.append(line.strip())
2108-
commits.reverse()
2113+
if self.commit != "":
2114+
if self.commit.find("..") != -1:
2115+
limits_ish = self.commit.split("..")
2116+
for line in read_pipe_lines(["git", "rev-list", "--no-merges", "%s..%s" % (limits_ish[0], limits_ish[1])]):
2117+
commits.append(line.strip())
2118+
commits.reverse()
2119+
else:
2120+
commits.append(self.commit)
2121+
else:
2122+
for line in read_pipe_lines(["git", "rev-list", "--no-merges", "%s..%s" % (self.origin, commitish)]):
2123+
commits.append(line.strip())
2124+
commits.reverse()
21092125

21102126
if self.preserveUser or gitConfigBool("git-p4.skipUserNameCheck"):
21112127
self.checkAuthorship = False
@@ -2215,8 +2231,9 @@ def run(self, args):
22152231
sync.branch = self.branch
22162232
sync.run([])
22172233

2218-
rebase = P4Rebase()
2219-
rebase.rebase()
2234+
if self.disable_rebase is False:
2235+
rebase = P4Rebase()
2236+
rebase.rebase()
22202237

22212238
else:
22222239
if len(applied) == 0:

t/t9807-git-p4-submit.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,46 @@ test_expect_success 'allow submit from branch with same revision but different n
155155
)
156156
'
157157

158+
# make two commits, but tell it to apply only one
159+
160+
test_expect_success 'submit --commit one' '
161+
test_when_finished cleanup_git &&
162+
git p4 clone --dest="$git" //depot &&
163+
(
164+
cd "$git" &&
165+
test_commit "file9" &&
166+
test_commit "file10" &&
167+
git config git-p4.skipSubmitEdit true &&
168+
git p4 submit --commit HEAD
169+
) &&
170+
(
171+
cd "$cli" &&
172+
test_path_is_missing "file9.t" &&
173+
test_path_is_file "file10.t"
174+
)
175+
'
176+
177+
# make three commits, but tell it to apply only range
178+
179+
test_expect_success 'submit --commit range' '
180+
test_when_finished cleanup_git &&
181+
git p4 clone --dest="$git" //depot &&
182+
(
183+
cd "$git" &&
184+
test_commit "file11" &&
185+
test_commit "file12" &&
186+
test_commit "file13" &&
187+
git config git-p4.skipSubmitEdit true &&
188+
git p4 submit --commit HEAD~2..HEAD
189+
) &&
190+
(
191+
cd "$cli" &&
192+
test_path_is_missing "file11.t" &&
193+
test_path_is_file "file12.t" &&
194+
test_path_is_file "file13.t"
195+
)
196+
'
197+
158198
#
159199
# Basic submit tests, the five handled cases
160200
#

0 commit comments

Comments
 (0)