Amr Elhosiny
Amr Elhosiny

Reputation: 257

Perforce - submit specific list of files from command line

I'm a p4 command line user. Typical use case, I search for a pattern in all files, open these files for edit, SED to replace the pattern, submit only those files modified.

How to do this from command ? Is there a way to create a new changelist, add these files to the changelist and submit the new changelist to default changelist.

Upvotes: 0

Views: 1590

Answers (1)

Samwise
Samwise

Reputation: 71562

The p4 -x global flag lets you pass the contents of a file (or stdin as -) to a p4 command as arguments. The p4 edit command accepts an arbitrary number of files arguments; the p4 submit command will operate on all open files by default.

C:\Perforce\test\grep>p4 print ...
//stream/main/grep/bar#1 - add change 145 (text)
wibble
//stream/main/grep/baz#1 - add change 145 (text)
wibble
//stream/main/grep/foo#1 - add change 145 (text)
weeble
//stream/main/grep/ola#1 - add change 145 (text)
weeble

C:\Perforce\test\grep>grep -l weeble * | p4 -x- edit
//stream/main/grep/foo#1 - opened for edit
//stream/main/grep/ola#1 - opened for edit

C:\Perforce\test\grep>sed -i -e s/weeble/wobble/ *

C:\Perforce\test\grep>p4 diff
==== //stream/main/grep/foo#1 - c:\Perforce\test\grep\foo ====
1c1
< weeble
---
> wobble
==== //stream/main/grep/ola#1 - c:\Perforce\test\grep\ola ====
1c1
< weeble
---
> wobble

C:\Perforce\test\grep>p4 submit -d "weeble wobble"
Submitting change 146.
Locking 2 files ...
edit //stream/main/grep/foo#2
edit //stream/main/grep/ola#2
Change 146 submitted.

Note that the p4 print and p4 diff commands in the above example are not necessary to submit the files; I just included that output to show the state of the files at those points in the process for purposes of understanding the example.

Upvotes: 1

Related Questions