I need to import the perforce depot workspace into linux development Environment.
I am getting error as p4passwd unset on p4 sync and login. Can anyone please explain this?
Run:
p4 set P4USER=your_user_name
p4 set P4CLIENT=your_client_name
where your_user_name is your actual Perforce username and your_client_name is the unique name you want to use to describe your workspace on this Linux machine. (If your Perforce username is the same as your Linux login, and you're fine with using your local hostname as the client name, you can skip this.)
Then run:
p4 login
and enter your Perforce password (not your Linux password).
Then run:
p4 client
Make any edits you like to the client spec. If you don't know what to do, just save it and exit the editor. The default will do to get you started.
Then run:
p4 sync
This will sync files from the depot to your workspace, according to your client spec. (If you just used the default client definition, everything in the depot is being synced to your current directory.)
https://www.perforce.com/perforce/doc.051/manuals/p4guide/03_quickstart.html
Related
I have a big problem and I can't understand this topic. I have a server with a website. I created a repository there with git init. Than I made a git add * to add all files from my server to the repository. Than I made a commit to commit all files to the repository.
Than I cloned it with git clone ssh://username#mysite.com/wordpress/.git to my local client.
All worked fine and I got a copy from my project. No I changed something on my local version and made a commit with a push. I looked in FileZilla but the content in the file don't changed. In the other direction when I changed something on the sever and pulled it to the local copy I saw the changes. Do you know why the changes which I made on the local copy are not visible on my sever?
Thank you for your help!
You need to push changes to a central repository that both your local machine and server can pull from (or add them as remotes for each other). A service such as GitHub works nicely for this. Here are instructions for a full workflow that works well for this. Updated instructions can be found in this gist. This workflow uses hooks to do the heavy lifting so that updates to your server are automated.
Using Git to Manage a Live Web Site
Overview
As a freelancer, I build a lot of web sites. That's a lot of code changes to track. Thankfully, a Git-enabled workflow with proper branching makes short work of project tracking. I can easily see development features in branches as well as a snapshot of the sites' production code. A nice addition to that workflow is that ability to use Git to push updates to any of the various sites I work on while committing changes.
You'll need to have Git installed on your development machines as well as on the server or servers where you wish to host your website. This process can even be adapted to work with multiple servers such as mirrors behind a load balancer.
Setting up Passwordless SSH Access
The process for updating a live web server relies on the use of post hooks within the Git environment. Since this is fully automated, there is no opportunity to enter login credentials while establishing the SSH connection to the remote server. To work around this, we are going to set up passwordless SSH access. To begin, you will need to SSH into your server.
ssh user#hostname
Next, you'll need to make sure you have a ~/.ssh in your user's home directory. If not, go ahead and create one now.
mkdir ~/.ssh
On Mac and Linux, you can harness the power of terminal to do both in one go.
if [ ! -d ~/.ssh ]; then mkdir ~/.ssh; fi
Next you'll need to generate a public SSH key if you don't already have one. List the files in your ~/.ssh directory to check.
ls -al ~/.ssh
The file you're looking for is usually named similarly to id_rsa.pub. If you're not sure, you can generate a new one. The command below will create an SSH key using the provided email as a label.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
You'll probably want to keep all of the default settings. This will should create a file named id_rsa in the ~/.ssh directory created earlier.
When prompted, be sure to provide a secure SSH passphrase.
If you had to create an SSH key, you'll need to configure the ssh-agent program to use it.
ssh-add ~/.ssh/id_rsa
If you know what you are doing, you can use an existing SSH key in your ~/.ssh directory by providing the private key file to ssh-agent.
If you're still not sure what's going on, you should two files in your ~/.ssh directory that correspond to the private and public key files. Typically, the public key will be a file by the same name with a .pub extension added. An example would be a private key file named id_rsa and a public key file named id_rsa.pub.
Once you have generated an SSH key on your local machine, it's time to put the matching shared key file on the server.
ssh user#hostname 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
This will add your public key to the authorized keys on the remote server. This process can be repeated from each development machine to add as many authorized keys as necessary to the server. You'll know you did it correctly when you close your connection and reconnect without being prompted for a password.
Configuring the Remote Server Repository
The machine you intend to use as a live production server needs to have a Git repository that can write to an appropriate web-accessible directory. The Git metadata (the .git directory) does not need to be in a web-accessible location. Instead, it can be anywhere that is user-writeable by your SSH user.
Setting up a Bare Repository
In order to push files to your web server, you'll need to have a copy of your repository on your web server. You'll want to start by creating a bare repository to house your web site. The repository should be set up somewhere outside of your web root. We'll instruct Git where to put the actual files later. Once you decide on location for your repository, the following commands will create the bare repository.
mkdir mywebsite.git
cd mywebsite.git
git init --bare
A bare repository contains all of the Git metadata without any HEAD. Essentially, this means that your repository has a .git directory, but does not have any working files checked out. The next step is to create a Git hook that will check out those files any time you instruct it to.
If you wish to run git commands from the detached work tree, you'll need to set the environmental variable GIT_DIR to the path of mywebsite.git before running any commands.
Add a Post-Receive Hook
Create a file named post-receive in the hooks directory of your repository with the following contents.
#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
Once you create your hook, go ahead and mark it as executable.
chmod +x hooks/post-receive
GIT_WORK_TREE allows you to instruct Git where the working directory should be for a repository. This allows you to keep the repository outside of the web root with a detached work tree in a web accessible location. Make sure the path you specify exists, Git will not create it for you.
Configuring the Local Development Machine
The local development machine will house the web site repository. Relevant files will be copied to the live server whenever you choose to push those changes. This means you should keep a working copy of the repository on your development machine. You could also employ the use of any centralized repository including cloud-based ones such as GitHub or BitBucket. Your workflow is entirely up to you. Since all changes are pushed from the local repository, this process is not affected by how you choose to handle your project.
Setting up the Working Repository
On your development machine, you should have a working Git repository. If not, you can create on in an existing project directory with the following commands.
git init
git add -A
git commit -m "Initial Commit"
Add a Remote Repository Pointing to the Web Server
Once you have a working repository, you'll need to add a remote pointing to the one you set up on your server.
git remote add live ssh://server1.example.com/home/user/mywebsite.git
Make sure the hostname and path you provide point to the server and repository you set up previously. Finally, it's time to push your current website to the live server for the first time.
git push live +master:refs/head/main
This command instructs Git to push the current main branch to the live remote. (There's no need to send any other branches.) In the future, the server will only check out from the main branch so you won't need to specify that explicitly every time.
Build Something Beautiful
Everything is ready to go. It's time to let the creative juices flow! Your workflow doesn't need to change at all. Whenever you are ready, pushing changes to the live web server is as simple as running the following command.
git push live
Setting receive.denycurrentbranch to "ignore" on the server eliminates a warning issued by recent versions of Git when you push an update to a checked-out branch on the server.
Additional Tips
Here are a few more tips and tricks that you may find useful when employing this style of workflow.
Pushing Changes to Multiple Servers
You may find the need to push to multiple servers. Perhaps you have multiple testing servers or your live site is mirrored across multiple servers behind a load balancer. In any case, pushing to multiple servers is as easy as adding more urls to the [remote "live"] section in .git/config.
[remote "live"]
url = ssh://server1.example.com/home/user/mywebsite.git
url = ssh://server2.example.com/home/user/mywebsite.git
Now issuing the command git push live will update all of the urls you've added at one time. Simple!
Ignoring Local Changes to Tracked Files
From time to time you'll find there are files you want to track in your repository but don't wish to have changed every time you update your website. A good example would be configuration files in your web site that have settings specific to the server the site is on. Pushing updates to your site would ordinarily overwrite these files with whatever version of the file lives on your development machine. Preventing this is easy. SSH into the remote server and navigate into the Git repository. Enter the following command, listing each file you wish to ignore.
git update-index --assume-unchanged <file...>
This instructs Git to ignore any changes to the specified files with any future checkouts. You can reverse this effect on one or more files any time you deem necessary.
git update-index --no-assume-unchanged <file...>
If you want to see a list of ignored files, that's easy too.
git ls-files -v | grep ^[a-z]
References
Deploy Your Website Changes Using Git
A simple Git deployment strategy for static sites
Using Git to manage a website
Ignoring Local Changes to Tracked Files in Git
pushing the code merely updates the remote repository's references.
It doesn't change the checked out working copy.
Consider that you could add a colleague's repository as a remote. If you pushed and the behaviour was that it would auto-checkout that new code, that would affect what they're working on.
It sounds like what you really want is a continuous integration tool, be it something full featured or merely an rsync triggered from a git hook.
you should only ever push to a bare repository (unless you know exactly what you are doing; and even then, you should only ever push to a bare repository).
you shouldn't clone a working copy's .git/ directory.
I have recently started using perforce on Windows 7. I have the perforce synced on my local machine using P4V. I was trying to run some other tool that uses the path where my perforce local directory is mapped on my machine. It appears that it is picking up the wrong one. While trying to debug, I noticed that the 'p4 info' command returns the 'Client root' which is set to the wrong value. The 'p4 set' shows the P4ROOT which is the correct value. What exactly is the difference between 'p4 set' and 'p4 info'? Can I update the 'Client root'?
P4ROOT is a server-side setting and is (confusingly) not related to your client root. The client root is set in the client spec that is specified via P4CLIENT and edited via the "p4 client" command.
To find the right value for P4CLIENT, look for the "Workspace" name in P4V ("workspace" is a synonym for "client"). Then tell the command line to use the same value like this:
p4 set P4CLIENT=(client name)
Once you do this, you should already have the right client root, but if you needed to update the client root, you'd do it by running:
p4 client
EDIT: RESOLVED! solution: all I did was to restart PC (not sure if this helped too), but then i logged id via console again, typed p4 client, it opened the cfg file, i closed it and then I also had to type: p4 set P4CONFIG="C:\workspace_directory\p4config.txt", now it's working.
original issue:
I'm trying to set up my first assembla project with perforce. "p4 info" is Ok, but I cannot run client without the error message. I already set up my connection settings into config file, if I type "p4info". Results:
Client name: my_name
Client host: my_host
Client unknown.
...the others seem to be fine
--name and host are fine, but I seem to need set up my client root workspace directory, but I was unable to find the way how to do it.
For me the reason was blank P4PORT. I added P4PORT manually and the error goes away.
export P4PORT="p4-host:port"
It is surprising that the P4PORT in p4v and p4 are not in sync. I had added p4port info in p4v and it works fine but for p4 i had to add manually.
I am getting a "client unknown" error when trying to commit any files from webstorm to perforce. My p4v is configured correctly and works outside of Webstorm and my p4 command line is also correctly configured yet when I use the exact same setup in webstorm I get the client unknown error. My client is setup and correctly copied into perforce. Any idea what might be going on here? Are there logs that will show me a more complete error?
For those who are facing this issue :
Check the "p4 info" output and see if "User name", "Client name" and Client are having correct data.
If they are 'none' / 'unknown', then check or set below environment variables
P4CLIENT
P4USER
P4PORT
P4CLIENT : Should match with your "workspace" name
P4USER : Username to login to perforce
P4PORT : Should have proper URL "HOSTNAME:PORT" of perforce server : Ex: 192.128.10.130:6666
I figured this out finally, though I ran into a new issue.
Resolution: The perforce client P4 (not P4v) has to be installed, and it was but it was not in the correct directory. P4 needs to be installed in your Applications on a Mac and that file needs to be made editable. You will also likely need to change your permissions for that file to allow system read/write access.
To make the file executable once it is in the Applications directory from the command prompt navigate to your applications directory and type: chmod +x p4 (http://www.perforce.com/perforce/doc.current/manuals/p4guide/01_install.html)
Then you can find the file in finder and right click it, the click get info from the context menu. From there at the very bottom will be file permissions. I set them all to read/write. You could also do this from the command line by typing chmod 755 p4 I think but I am not great on the command line so use at your own risk.
As far as your workspace is concerned that should be whatever your workspace is set to in P4V.
At that point if you hit test connection inside Webstorm->preferences->perforce it should work or at least give you a new error with some more information.
Mine was able to connect successfully but now when I try to update a file I get an error saying "path '/users/my-path.....' is not under the client's root '/users/my-path' even though the first path specified is clearly a child of the second path. Still working on this error.
Mine was able to connect successfully but now when I try to update a file I get an error saying "path '/users/my-path.....' is not under the client's root '/users/my-path' even though the first path specified is clearly a child of the second path. Still working on this error.
In my case i resolve this problem -> i had physical way to my files /Users/.... but in perforce i had a root like /users/.... (in lowercase), i change root and its help for me in mac
Surprizing little documentation on setting this up, so I'm sure this is a setup problem.
Steps to reproduce:
Open terminal (p4.exe in PATH)
type p4 [RET]
Hangs indefinitely. When I issue commands from emacs (ie p4 edit [file] it eventually comes back with
Perforce client error:
Connect to server failed; check $P4PORT.
TCP connect to perforce failed.
perforce: host unknown.
The error message that is displayed when called from emacs points in the right direction, p4 can't find your perforce server (the default is perforce, that's where the perforce: host unknown comes from.
Make sure to either specify -p for your call to p4 or set the environment variable P4PORT. Beware, despite the name, P4PORT includes the hostname of the perforce server.
p4 -p serverhost:1666
I'm not sure why p4 would hang indefinitely on the CLI and return after some time when called from emacs.
In my case I set these variables in order to get it to work (very annoying it just hangs instead of complaining of the missing configuration).
P4PORT
P4USER
P4CONFIG
P4EDITOR
Please check if a p4 process running in background in the same shell. you need to stop already running process.