I am quite new to P4 and being a junior dev I am having some issues when trying to automate merges from streams, I am running p4 merge, and then p4 resolve -am, then I build the project and run some tests and if everything goes well I want to submit otherwise shelve the files so a engineer can go through the conflicts, and manually resolve them and submit. The thing is that the p4 shelve command as far as I know needs to have -c <CL#> argument, and I do not know how or where I can get the CL number I just generated when running the script. Is there any way to do this? or any documentation that can help me with this?
The shelve command does not require a -c argument.
C:\Perforce\test\python>p4 help shelve
shelve -- Store files from a pending changelist into the depot
p4 shelve [-Af] [-p] [files]
p4 shelve [-Af] [-a option] [-p] -i [-f | -r]
p4 shelve [-Af] [-a option] [-p] -r -c changelist#
p4 shelve [-Af] [-a option] [-p] -c changelist# [-f] [file ...]
p4 shelve [-As] -d -c changelist# [-f] [file ...]
...
By default, 'p4 shelve' creates a changelist, adds files from the
user's default changelist, then shelves those files in the depot.
If you just ran p4 merge and p4 resolve -am, the files are open in your default changelist. Running p4 shelve with no arguments will automatically create a new changelist out of those files and shelve it, and it will display the number of the new changelist, so all your script needs to do is print the result of the command.
Related
How can I get the perforce root directory path. I've searched online and I've tried solution such as
p4 -F %clientRoot% -ztag info
However the results returned were empty, but when i run this command:
p4 clients -u jmartini
I get these results:
Client jma_HP001 2017/10/19 root C:\projects\john 'Created by
jmartini. '
How can I simply just get the root directory path from command line. I would expect my results to be this:
C:\projects\john
If p4 info doesn't return the current client root, your shell does not have P4CLIENT set correctly. To fix this, you can do:
p4 set P4CLIENT=jma_HP001
From this point on, other commands (including the p4 -F %clientRoot% -ztag info you tried to run first) will return results relative to that client workspace.
If you want to just get the client root out of the clients command you can do:
p4 -F %domainMount% clients -u jmartini
or:
p4 -Ztag -F %Root% clients -u jmartini
Note that if the user owns multiple clients this will get you multiple lines of output.
To figure out the formatting variables you can use with the -F flag, try running commands with the -e or -Ztag global options:
p4 -e clients -u jmartini
p4 -Ztag clients -u jmartini
More on the -F flag in this blog article: https://www.perforce.com/blog/fun-formatting
How can I source the branch name from node ID in Mercurial?
I have tried hg id nodeid but that doesn't work
But hd id nodeid does work, provided you spell the node identifier with the -r or --rev option:
$ hg id -r 2
db6f6e1d8715 (sidebr) tip
Note that if the branch name is default it is suppressed, as usual.
To get just the branch name, and avoid suppressing the name default, add the -b option:
$ hg id -b -r 1
default
Note that you can get more than one piece of information:
$ hg id -i -b -n -r 1
d05b1df8b8f6 1 default
(The order is always hash, rev, branch when using these options, regardless of the order of the -i / --id, -n / --num, and -b / --branch options. Adding -t / --tags and/or -B / --bookmarks adds the tags and the bookmarks in that order, again regardless of option order.)
I have a perforce sandbox, and I have created a new changeset in the sandbox, which is still pending, i.e. I have not submitted it yet. How do I obtain the changeset number. p4 changelists gives me changelists for all sandboxes, I only need for mine, and that only the pending one.
p4 changes -c CLIENT -s pending
where CLIENT is the name of your client spec ("sandbox").
From "p4 help changes":
changes -- Display list of pending and submitted changelists
changelists -- synonym for 'changes'
p4 changes [-i -t -l -L -f] [-c client] [ -e changelist# ]
[-m max] [-s status] [-u user] [file[revRange] ...]
...
The -c client flag displays only submitted by the specified client.
...
The -s status flag limits the output to changelists with the specified
status. Specify '-s pending', '-s shelved', or '-s submitted'.
I want to keep my linux config in fossil scm system.
Here is what I did at initial stage.
$ cd /
$ fossil new b.fsl
$ fossil open b.fsl
$ fossil add etc/group
$ fossil add boot/grub/menu.lst
$ fossil ci -m 'init commit'
I want do do things like (operate like hg/git).
$ cd etc
$ fossil status group
$ fossil add motd
It will show error message:
fossil: current directory is not within an open checkout
So, my temp dirty solution is
$ cd /
$ fossil status etc/group
$ fossil add etc/motd
$ fossil add /etc/motd # this line will cause problem
For my git/hg experiences, it should work.
$ cd /
$ hg init
$ hg add etc/group boot/grub/menu.lst
$ hg ci -m 'init commit'
$ cd etc
$ hg status group # it works
$ hg add motd # it works too
Before the command
$ fossil new b.fsl
Type the command
$ cd etc
If you want the fossil repo stored in another folder, change the commands
$ fossil new b.fsl
$ fossil open b.fsl
to
$ fossil new path_to_repo/b.fsl
$ fossil open path_to_repo/b.fsl
All mentioned commands "add" and "status" and all fossil commands related to the checkout must be executed when the current directory is set somewhere inside the directory tree of the checkout.
You can't specify the checkout directory yourself as a command line option.
It seems there is a bug (or intentionally introduced feature) in fossil that prevents it searching for the open checkout file (".fslchkout" or "FOSSIL") up to the root directory. That is why in this case you must be in the root directory when you execute commands on this checkout.
Of course all executions of fossil in this case must be with root privileges. Otherwise, even in the root directory you will get "not within checkout" error.
This situation is covered in great detail in the User Guide, which I recommend wholeheartedly.
http://www.fossil-scm.org/schimpf-book/home
In particular, see version 2.0 of the fossilbook.pdf, in section 2, entitled "Single Users", the section starting with:
I have a directory called FOSSIL in which I keep all my repositories, Fossil doesn’t care but it helps me to keep them all in one place so I can back them up.
The first command there shows how to call relative directories:
$ fossil new ../FOSSIL/FossilBook.fossil
repo status shows me a lot of un-wanted changes.
It would be duplicated if I enter every project and use git reset --hard.
Is there a way to reset all the changes using repo, something like repo reset --hard?
This is the command I use for this kind of things, very useful
repo forall -vc "git reset --hard"
What everything mean here ?
the repo forall will execute for all repos.
the -v is verbose, so it will print the output of the command
the -c "COMMAND TO EXECUTE" is the actual command you want
If there is a need to revert working folder to the clean state where you don't have local modifications and no untracked files (i.e. where repo status shows nothing), I found these two approaches useful on repo sync and deleted/modified files
repo forall -c 'git reset --hard ; git clean -fdx'
or
rm -rf * ; repo sync -l
// note that .repo is preserved after that
Note, that this is not equivalent to initializing a new local repo and syncing (e.g. stash is preserved)
If you are not sure what is going on, please read the full thread repo sync and deleted/modified files
You can use the repo command as the following to revert all your changes:
repo sync -d
This will revert all your changes back to original revision.
Edited:
The command above is working only with the version at that time.
The working command is :
repo forall -vc "git reset --hard"
The command and options description
forall
Executes the given shell command in each project
Options (that can be used with the forall command)
-c: command and arguments to execute. The command is evaluated through /bin/sh and any arguments after it are passed through as shell
positional parameters.
-p: show project headers before output of the specified command. This is achieved by binding pipes to the command's stdin, stdout, and
sterr streams, and piping all output into a continuous stream that is
displayed in a single pager session.
-v: show messages the command writes to stderr.
For more information please refer the repo document
I use the repo forall command with the below syntax and it helps me to reset the tracking files.
repo forall -p -c 'git checkout -f foo'
where foo should be replaced with a legitimate branch name.
repo forall does not cover all of the git tree
#!/bin/bash
for gitdir in $(find . -type d -name .git -prune); do
pushd $(dirname $gitdir)
git reset --hard
popd
done