Complex examples of command aliases
You can define aliases for complex commands by using redirection and special operators.
Before you can define an alias, you must create an alias file. See Define a command alias.
On this page:
Cherry picking
This alias definition:
cherry-pick-change $(cl) $(s) $(t) = integrate //depot/$(s)/...@$(cl),$(cl) //depot/$(t)/...
turns the command:
p4 cherry-pick-change 1015978 p15.2 main
into:
p4 integrate //depot/p15.2/...@1015978,1015978 //depot/main/...
Another cherry picking example that creates a little merge script:
cherry-pick $(cl) $(s) $(t) $(msg) = \
integrate //depot/$(s)/...@$(cl),$(cl) //depot/$(t)/... &&
resolve -am -Ac //depot/$(t)/... &&
submit -d $(msg) &&
sync
You could then execute a command like the following:
p4 cherry-pick 1015978 two one "line a merged into one"
which would run the following commands:
p4 integrate //depot/two/...@1015978,1015978 //depot/one/...
p4 resolve -am -Ac //depot/one/...
p4 submit -d "Cherry-pick change https://swarm.perforce.com/@1015978[1015978]
from //depot/two/... to //depot/one/..."
p4 sync
Simple pipelining
Starting with a simple example:
newStreamsDepot $(dpt) = depot -o -t stream $(dpt) > $(depotSpec) &&
depot -i < $(depotSpec)
Note that when using redirection, the $ variables used
in the transformation side of the definition do not need to
correspond to the arguments specified on the left side of the
equation. In the example above, depotSpec is a variable
created during the execution of the newStreamDepot
alias.
Here are aliases for merge down copy up:
mergedown $(b) = fetch &&
switch $(b) &&
merge &&
resolve -am &&
submit -d "Merged down from main"
copyup $(b) = switch dev &&
merge --from $(b) &&
resolve -as &&
submit -d "Copied up from $(b)" &&
push
# Note the use of the branch name in the submit message of the copyup alias.
DVCS: Aliases to communicate with multiple servers
Use aliases like the following when copying spec objects from the shared server to your personal server.
copy-user $(p4port) = -p $(p4port) user -o $(u) > $(spec) &&
user -i < $(spec)
copy-job $(p4port) $(j) = -p $(p4port) job -o $(j) > $(spec) &&
job -i < $(spec)
copy-stream $(p4port) $(s) = -p $(p4port) stream -o $(s) > $(spec) &&
stream -i < $(spec)