Jump to content


How to shelve a change with one liner from CLI?

shelve cli p4 shelve

  • Please log in to reply
6 replies to this topic

#1 mcru

mcru

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 14 February 2017 - 04:40 PM

Hi - I was hoping someone may have an example of how you can shelve a changelist from the command line with a one liner. My problem is getting the description field filled out.

Is my only option to generate an entire changelist description and read it into p4 shelve with the -i flag?

#2 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 14 February 2017 - 05:15 PM

Originally posted to the perforce-user mailing list by: Michael Mirman


It can still be a one liner - with shelve -i:

p4 --field Description=test change -o | p4 shelve -i

HTH,

--
Michael Mirman
MathWorks, Inc.
3 Apple Hill Drive, Natick, MA 01760
508-647-7555

Quote

-----Original Message-----
From: perforce-user [mailto:perforce-user-bounces@perforce.com] On
Behalf Of mcru
Sent: Tuesday, February 14, 2017 11:45 AM
To: perforce-user@perforce.com
Subject: [p4] How to shelve a change with one liner from CLI?

Posted on behalf of forum user 'mcru'.

Hi - I was hoping someone may have an example of how you can shelve a
changelist
from the command line with a one liner. My problem is getting the
description
field filled out.

Is my only option to generate an entire changelist description and read it into
p4 shelve with the -i flag?



--
Please click here to see the post in its original format:
  http://forums.perfor...ow-to-shelve-a-
change-with-one-liner-from-cli
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user



#3 tkosinski

tkosinski

    Advanced Member

  • Sandbox Beta
  • PipPipPip
  • 73 posts

Posted 14 February 2017 - 05:46 PM

Alternatively, when you open it into a pending changelist (other than the default pending changelist), doing something like:

p4 shelve -c <changelist number> //path/to/file


will work.

#4 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 14 February 2017 - 06:25 PM

Originally posted to the perforce-user mailing list by: Michael Mirman


If you already have a file in a pending numbered change, you can
p4 shelve -c changenumber
I am not sure what significance the file path is on that command - especially if I have multiple files in the change.

However, the numbered change needs to be created first. I can do it in a one liner like this
env P4EDITOR=/bin/true p4 --field Description=test change
but then I need to capture the change number and plug it in to the shelve command (yes, we can construct an awk getting the change number from p4 change, but it gets unnecessarily complicated IMHO).

--
Michael Mirman
MathWorks, Inc.
3 Apple Hill Drive, Natick, MA 01760
508-647-7555

Quote

-----Original Message-----
From: perforce-user [mailto:perforce-user-bounces@perforce.com] On
Behalf Of tkosinski
Sent: Tuesday, February 14, 2017 12:50 PM
To: perforce-user@perforce.com
Subject: Re: [p4] How to shelve a change with one liner from CLI?

Posted on behalf of forum user 'tkosinski'.

Alternatively, when you open it into a pending changelist (other than the
default pending changelist), doing something like:



p4 shelve -c <changelist number> //path/to/file
will work.



--
Please click here to see the post in its original format:
  http://forums.perfor...ow-to-shelve-a-
change-with-one-liner-from-cli
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user



#5 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 979 posts

Posted 14 February 2017 - 06:42 PM

View PostMailman Sync, on 14 February 2017 - 06:25 PM, said:

However, the numbered change needs to be created first. I can do it in a one liner like this
env P4EDITOR=/bin/true p4 --field Description=test change

Just as a fun exercise: if you did want to first create the change and then shelve it (just for the sake of being needlessly complicated) here's how you could do it without needing any external utilities at all:

p4 --field "Description=blah" change -o | p4 -F "shelve -c %change%" change -i | p4 -x - run

I *think* you could even get the "p4 edit" in the middle there and keep passing the changelist number from command to command...  :D

#6 Mailman Sync

Mailman Sync

    Advanced Member

  • Maillist Aggregator
  • 2495 posts

Posted 14 February 2017 - 08:05 PM

Originally posted to the perforce-user mailing list by: Michael Mirman


I didn’t think of creating a whole command in -F!
Thank you for the idea!
Very cool!
:-)

--
Michael Mirman
MathWorks, Inc.
3 Apple Hill Drive, Natick, MA 01760
508-647-7555

Quote

-----Original Message-----
From: perforce-user [mailto:perforce-user-bounces@perforce.com] On
Behalf Of Sambwise
Sent: Tuesday, February 14, 2017 1:45 PM
To: perforce-user@perforce.com
Subject: Re: [p4] How to shelve a change with one liner from CLI?

Posted on behalf of forum user 'Sambwise'.



[http://forums.perfor...dule=forums
tion=findpost&pid=21156]
Mailman Sync, on 2017/02/14 18:25:10 UTC, said:

Quote

   However, the numbered change needs to be created first. I can do it in a
one liner like this

Quote

  env P4EDITOR=/bin/true p4 --field Description=test change

Just as a fun exercise: if you did want to first create the change and then
shelve it (just for the sake of being needlessly complicated) here's how you
could do it without needing any external utilities at all:

p4 --field "Description=blah" change -o | p4 -F "shelve -c
%change%" change -i | p4 -x - run



--
Please click here to see the post in its original format:
  http://forums.perfor...ow-to-shelve-a-
change-with-one-liner-from-cli
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user
_______________________________________________
perforce-user mailing list  -  perforce-user@perforce.com
http://maillist.perf...o/perforce-user




#7 mcru

mcru

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 14 February 2017 - 10:43 PM

Michael, I love your suggestion of "p4 --field Description=test change -o | p4 shelve -i". This works beautifully. Originally I was writing a change description file that I read into the shelve command... huge pain.

Anyway, this was the last piece in the puzzle for mimicking git-esque pull request workflow! I now have an alias that takes the contents of a task stream, copies the changes up to the parent branch, creates a shelved changelist w/ #review to open up a review in swarm, reverts the changes on the parent branch, and switches back to the dev branch. I'm going to add args to accept a code review ID so I can append shelves to existing reviews, and probably extend swarm to unload task branches when code review is approved/committed (if all changes have been merged into parent). If anyone's interested in details, I can expand on this...





Also tagged with one or more of these keywords: shelve, cli, p4 shelve

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users