Roger Lipscombe
Roger Lipscombe

Reputation: 91835

Can you "ignore" a directory in P4V?

We use Visual Studio, which generates lots of bin and obj directories. When I use P4V's "Reconcile Offline Work" feature, these appear in the "Local files not in depot" list.

I'd like to exclude them. I found this question, but that talks about files, and when I try what it suggests (adding the following to my workspace view), it doesn't work:

//depot/Foo/... //Client/Foo/...
-//depot/Foo/.../*.user //Client/Foo/.../*.user
-//depot/Foo/.../bin/... //Client/Foo/.../bin/...
-//depot/Foo/.../obj/... //Client/Foo/.../obj/...

It doesn't actually seem to work for files, either: the foo.csproj.user files are still displayed in the list.

Can I exclude directories from P4V? If so, how? What am I doing wrong?

Upvotes: 53

Views: 60995

Answers (8)

Dmitry Labadin
Dmitry Labadin

Reputation: 33

Method won't work with local depot, but if you have a stream depot, you can create a virtual stream and exclude your binaries folders in centralized way for all developers.

Advanced path settings of virtual stream could be something like that:

share ...
exclude bin/...
exclude logs/...

https://www.perforce.com/manuals/p4v/Content/P4V/streams.virtual.html

Upvotes: 0

Dmytro Kryvoruchenko
Dmytro Kryvoruchenko

Reputation: 96

When I added the folders to ignore, they were not applied because I specified the path to the folders, and it was a mistake, you just need to specify the name of the folder that you want to ignore.

Upvotes: 0

Thariama
Thariama

Reputation: 50832

Updated answer: This has been somewhat tricky in the past, because there was no built-in way to exclude a directory from a Perforce command. Since 2012 this has changed. You can have a look at a nice perforce article for this problem.

As of 2012.1, the P4IGNORE environment variable can be set to designate a file to be used to exclude files from Perforce. Both the Perforce Server (p4d) and client (p4, P4V) need to be 2012.1 or greater. P4IGNORE's purpose is to ignore files when adding new files to the depot and reconciling workspaces. Like comparable features in other version control systems, P4IGNORE cannot be used to ignore files already under the repository's control.

P4Eclipse manages .p4ignore files on its own terms. (see the manual regarding this point here)

Using client views to exclude files and directories:

The traditional method for excluding files and directories in Perforce is to use exclusionary client mappings. See the command reference for Views for full documentation. Example view:

View:

//depot/... //test_ws/depot/...
-//depot/dir/etc/... //test_ws/depot/dir/etc/...

This view will prevent files in dir/etc from being added to the depot. If trying to exclude the directory from read-only queries, use client or relative syntax.

$ p4 files //depot/dir/etc/...
//depot/dir/etc/foo#1 - add change 1186 (text)
//depot/dir/etc/bar#1 - add change 1186 (text) 


$ p4 files //test_ws/dir/etc/...
//test_ws/test_ignore/ignoredir/... - file(s) not in client view. 

$ cd dir/etc
$ p4 files ...
... - file(s) not in client view.

Alternatively, you can use shell commands to filter your output as desired.

p4 files //depot/dir/... |
    awk -F# '{print $1}' |
    grep -v "//depot/dir/etc/" |
    p4 -x - fstat

which runs p4 fstat on all files under "//depot/dir/", except for those files under "//depot/dir/etc/". This directory exclusion is accomplished by listing all of the files, and then using grep to remove those files under the directory to be excluded. The trailing slash in "//depot/dir/etc/" is necessary to prevent matching directories under "//depot/dir/" that start with "etc" (for example, "//depot/dir/etc2009").

Note:

The awk command assumes there are no file names containing the "#" character. The grep command can also read its patterns from a file, which is useful if you need to exclude multiple directories. We use the '-x -' flags with the p4 command to use the input as arguments to the corresponding command; see the Perforce Command Line Global Options for more information.

Upvotes: 8

Clint StLaurent
Clint StLaurent

Reputation: 1268

There is a way to do it directly in Perforce:

  • Connection menu
  • Edit Current Workspace...

Navigate the project tree. Right-click on the file or folder. Choose to include or exclude the file, the folder, the entire tree.

Upvotes: 7

raven
raven

Reputation: 18135

As of version 2012.1, Perforce supports the P4IGNORE environment variable. This allows you to specify files and directories to ignore when using the commands that search for or add new files (p4 add, p4 status, and p4 reconcile).

To use an ignore file, create a file in the root of your workspace and give it some meaningful name. The convention seems to be something like .ignore or .p4ignore, but anything will do (I used p4ignore.txt so that I can edit it with a simple double-click). Then fill it with your ignore rules. The following will ignore the the unwanted debris generated by Visual Studio:

# directories
bin
obj

# files
*.suo
*.user

After you have created this file, set the P4IGNORE environment variable to point to it. At the command line, type something along the lines of this:

p4 set P4IGNORE=C:\somepath\p4ignore.txt

Be sure to use an absolute path! The Perforce documentation doesn't specify this and my first attempt did not work (on Windows anyway) because I didn't specify an absolute path.

After doing this, any attempt to add files or directories that are in the ignore list will be rejected and you'll see a warning such as this (which they do give you the option to suppress):

P4V 'ignored' files message


If you are using a version of the Perforce server previous to 2012.1, you can still do this in your client spec. The syntax of your exclusion rules is just a little off. What you want is this:

-//depot/Foo.../*.user //Client/Foo.../*.user
-//depot/Foo...bin/... //Client/Foo...bin/...
-//depot/Foo...obj/... //Client/Foo...obj/...

Note the missing slashes after "Foo" and before "bin" and "obj".

Upvotes: 77

funroll
funroll

Reputation: 37093

This works great for me:

//depot/... //my_workspace_name/...
-//depot/.../.git/... //my_workspace_name/.../.git/...
-//depot/.../xcuserdata/... //my_workspace_name/.../xcuserdata/...
-//depot/.../xcschemes/... //my_workspace_name/.../xcschemes/...
-//depot/.../xcdebugger/... //my_workspace_name/.../xcdebugger/...

Upvotes: 3

Toby Allen
Toby Allen

Reputation: 11213

This may not be relevant, but if there are spaces in any of your paths you need to ensure you have correctly enclosed them in "" but dont enclose the - inside the quotes.

Upvotes: 1

Chance
Chance

Reputation: 2700

I would go ahead with the Reconcile Offline Work and do everything but the submit. Before the submit, do the following:

p4 revert //Client/Foo/.../*.user

p4 revert //Client/Foo/.../bin/...

p4 revert //Client/Foo/.../obj/...

It's not automated, but that's the best I can think of at the moment.

Upvotes: -1

Related Questions