Making a production build of a PHP project with Subversion - php

If you are working in PHP (or I guess any programming language) and using subversion as your source control, is there a way to take your project (for example):
C:\Projects\test\.svn
C:\Projects\test\docs\
C:\Projects\test\faq.php
C:\Projects\test\guestbook.php
C:\Projects\test\index.php
C:\Projects\test\test.php
and build/copy/whatever it so it weeds out certain files and becomes:
C:\Projects\test\faq.php
C:\Projects\test\guestbook.php
C:\Projects\test\index.php
automatically? I'm getting tired of making a branch, and then going through the branch and deleting all of the ".svn" folders, the docs directory, and my prototyping files.
I know I could probably use a .bat file to only copy the specific files I want, but I was hoping there was some way with subversion to sort of pseudo ignore a file, to where it will still version it, but where you could make a snapshot of the project that ignores the files you told it to pseudo ignore.
I know I read online somewhere about some functionality that at least lets you copy without the .svn folders, but I can't find it now.

If you use TortoiseSVN, you can use the export feature to automatically strip out all of the .svn files. I think other svn things have the same feature.
Right click the root project folder, then select TortoiseSVN > Export, and tell it where you want the .svn free directory.

Copy all the files manually or using your existing method for the first time. Then, since I take it you're on a Windows platform, install SyncToy and configure it in the subscribe method, which would effectively one-way copy only the changes made since the last pseudo-commit to production for files already in production. If you want to add a file you can just copy it manually and resume the SyncToy operation.

Ok, so my final solution is this:
Use the export command to export to a folder called "export" in the same directory as a file called "deploy.bat", then I run the deploy script (v1 stands for version 1, which is what version I am currently on in this project) This script utilizes 7-Zip, which I have placed on my system path so I can use it as a command line utility:
rem replace the v1 directory with the export directory
rd /s /q v1
move /y export\newIMS v1
rd /s /q export
rem remove the prepDocs directory from the project
rd /s /q v1\prepDocs
rem remove the scripts directory from the project
rd /s /q v1\scripts
rem remove individual files from project
del v1\.project
rem del v1\inc\testLoad.html
rem del v1\inc\testInc.js
SET /P version=Please enter version number:
rem zip the file up with 7-Zip and name it after whatever version number the user typed in.
7z a -r v%version%.zip v1
rem copy everything to the shared space ready for deployment
xcopy v%version%.zip /s /q /y /i "Z:\IT\IT Security\IT Projects\IMS\v%version%.zip"
xcopy v1 /s /q /y /i "Z:\IT\IT Security\IT Projects\IMS\currentVersion"
rem keep the window open until user presses any key
PAUSE
I didn't have time to check out the SyncToy solution, so don't take this as me rejecting that method. I just knew how to do this, and didn't have time to check that one out (under a time crunch right now).
Sources:
http://commandwindows.com/command2.htm
http://www.ss64.com/nt/

Related

How to exclude the unit test directory in Git

A large existing PHP project that is having Unit Tests retrofitted to it. I want to have a "tests" directory in the code on the development branch which contains these unit tests and perhaps the DB fixtures also. Naturally I don't want anything in there making its way onto the production environment so I want a way of automatically excluding this directory when it's deployed. Or ideally, a way to avoid anything in there that is committed from being merged into master in the first place.
How do I manage this? There will be frequent and unpredictable commits to the test directory so I can't simply skip certain commits manually.
EDIT: I've now got four answers telling me about .gitignore. I don't believe .gitignore is appropriate here because I want to exclude something that IS to be committed but only from a specific branch.
it's called .gitignore
From the docs:
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected
source: https://git-scm.com/docs/gitignore
For examples sake, let's say you have this working tree:
|-app
|-test
|-index.php
to exclude test/ the test directory add a .gitignore on the same level as the .git folder and in it just add:
test/
commit the git ignore and make a change/add a file to test/ and you'll notice it doesn't appear when you run
$ git status
You can use .gitignore. This is a file in your project root and you can list all files and directories you don't want to commit/push. They are separated by a new line.
I've found that the way to keep a part of a branch from being merged into another branch on a permanent basis is to use sub-modules.
I created my unit tests folder as its own repository and then included it in my mainline branch (which is not the production/master branch) as a sub-module.
https://git-scm.com/book/en/v2/Git-Tools-Submodules
By default when you clone a repository, sub-modules are not cloned with it. The sub-module directory is created but remains empty, unless you also execute
git submodule init
git submodule update
Therefore it's as simple as not including the above commands in your production git clone but including them when you clone the repository for testing or development. You can make any changes to the tests directory along with the codebase and commit both together. This means tests can be developed alongside the code base without risking them being deployed to production.
I found the following aliases useful to set up to streamline git operations:
$ git config alias.sdiff '!'"git diff && git submodule foreach 'git diff'"
$ git config alias.spush 'push --recurse-submodules=on-demand'
$ git config alias.supdate 'submodule update --remote --merge'
This seems to be the correct approach to solving the problem of wanting separation of code in a single repository to be different on a per-branch basis.

Automatically `pull` when there is what to pull to my repo: `post-merge` git server hook using PHP

What I want to accomplish:
I have juts installed git on my development server.
I create a branch out of my 'develop' branch, work on my new feature branch, commit, and when I'm done - I merge the new feature branch with the 'develop' branch.
To apply the changes for the 'develop' branch on my development server I have to log in to my server and use git pull - which I'm trying to prevent and happen automatically - when there is something to pull from my development server - it will be done automatically.
I hope I'm clear about that I'm trying to accomplish ;)
What I have done up till now is:
Created a folder inside my project /www/hooks/ and added a file called post-merge: Following git documentation - this should get triggered whenever I merge a branch.
Inside this folder I added the text:
which should execute whatever is in between the backticks symbol ( ` ) as a shell command (following this PHP documentation)
Inside the folder /www/.git/hooks/ I added a symbolic-link to the file I previously mentioned with the same exact name: /www/hooks/post-merge :
sudo ln -s -f /www/hooks/post-merge /www/.git/hooks/post-merge
I gave the linked file under /www/.git/hooks/post-merge 775 file permission as the other files.
Some notes:
My repo is on Bitbucket
My directory /www/homepage/ is the one with the index file, so nothing can run outside of it on a browser (apache2 points to it..) - (but i guess there shouldn't be a problem since it's self executed via /.git/hooks ?)
I tried renaming both my files (the one under /www/.git/hooks/ & /www/hooks/) to post-merge.php and this didn't work.
just to have Carriage return
#!/bin/bash
git --git-dir "path/master/.git" --work-tree "path/master" pull origin master
you could try this in your post-merge

Getting specific folder structure from git

i have some files and folder in my git repo. But some of them have a very long path that when i try to synchronize my workspace with git it gives me an error because windows cannot have characters in a path more than 260. Is there a way to pull specific files and folders? for example *.php files from /file/*.php?
I do not know much from git and also all other tutorials and answers i found here do not work. i even tried the git git_core.longpathenabled true but nothing happened.
Any ideas?
Is there a way to pull specific files and folders
Yes, you can use git filter-branch and or git subtree split
Sample code:
filter-branch
# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
This will checkout all your desired files from the given folder to the current directory
subtree split
git subtree split -P <name-of-folder> -b <name-of-new-branch>
If your repository is hosted on Github or similar, you can download the file individually over HTTP, but you obviously will not be able to push changes.
Finally, if your copy of the repo is located in a deeply-nested folder you could move it somewhere like Users\You\Projects\cloned.

xdebug across projects in netbeans

Here is the situation.. I have some classes that are in one project... My main code is in another project... and i split this up because i am using GIT as my SCM... So when i debug my main code... i would like to step into the classes and debug them, but xdebug won't let me step into them... and i assume its because the classes are in another project... any ideas?
Thanks in advance...
I've run into this as well. I am going to assume that the way your projects look when they are deployed is that the classes in the separate project are copied into some directory somewhere in the main code.
Let's assume the separate project contains only one class, Foo, for simplicity's sake. Let's assume, too, that Foo is present in the deployed "main code" in the directory and file /maincode/external/lib/Foo.php. Finally, let's assume that /maincode/external/lib exists as a directory in your version-controlled "main code" project, and that it contains only a place-holder file and is otherwise empty.
First, use one of the many methods git provides to ignore the contents of the /maincode/external/lib directory in your NetBeans project directory for that project. We're going to make it look like it contains some stuff, and we don't want this directory, that is otherwise supposed to be empty, to get changes committed to it by mistake.
Now that it is ignored, make a symbolic link in that directory to Foo.php over in the other project. In Unix, you want the ln command, e.g.
ln -s /path/to/project/files/MyFooProject/Foo.php Foo.php
In Windows, you are looking for the mklink command, e.g.
mklink Foo.php C:\path\to\project\files\MyFooProject\Foo.php
Give NetBeans a moment or two to think about it (or force the issue by invoking the "Scan for external changes" command in the "Source" menu), and you should see Foo.php show up in the "maincode" project where you made the symbolic link.
Now, when you are tracing through execution and need to step into Foo.php to see what the Foo class is doing, you will step into the one that is in the "maincode" project. Since it is a symbolic link over to the file in the "MyFooProject" project, however, any chanes you make will be reflected over there.
Just be sure to unlink everything (the normal rm commmand in Unix, and the usual del command in Windows, but in the directory where the symbolic link is!) when you are through. Also, if there were things in the directory that you ignored that you want to be able to commit, then un-ignore that directory.
If you need to do this for more than just one file, then you can link whole directories. If, instead of the above, you normally copy the contents of "MyFooProject" into the directory /maincode/external/lib/myfoo/ in the deployed version, then just link the appropriate directory like you did the file above. In Windows, for example,
cd \path\to\project\files\maincode\external\lib
mklink /D myfoo C:\path\to\project\files\MyFooProject
That will make a symbolic directory link. It has been a while since I did anything like that on Unix, so I don't remember the exact command for the same thing on that OS (or if symbolic directory links are even possible on Unix). Once the directory is linked, you should see the new directory plus all of the files and subdirectories show up in your NetBeans "maincode" project, ready for your execution-tracing pleasure.
Again, remember to unlink and un-ignore everything once you are done, lest you wake up the next morning to find yourself confused. :) To unlink the directory in windows...
cd \path\to\project\files\maincode\external\lib
rmdir myfoo
and it should unlink. (Just be careful when you are deleteing and rmdir'ing that you are doing it to the symbolic link!)

.hgignore for a CakePHP application?

We're using CakePHP for a new application, and we use Mercurial as the source control tool. (Mercurial uses one .hgignore file in the root directory, unlike (for example) CVS that uses .cvsignore in any directory.)
I'd like to exclude the content of the app/tmp/ directory from the source control (since they change all the time, and can be regenerated), but I can't add app/tmp/* to .hgignore, since then the standard directories under tmp (cache, logs, sessions, tests, and also cache/models, cache/persistent, ...) would be missing from new clones made by hg clone, resulting in errors.
Currently I have in my hgignore:
app/tmp/logs/*.log
app/tmp/cache/persistent/cake_*
app/tmp/cache/models/cake_*
It would be good to have a "standard" one that could be used in all projects. Can someone suggest a complete solution?
You can add
syntax: glob
app/tmp/**
to your .hgignore file and Mercurial will from that point on ignore all files under app/tmp/ with the exception of files tracked by Mercurial. See hg help patterns for more about file name patterns.
So if you do
% touch app/tmp/cache/.empty
% touch app/tmp/logs/.empty
% hg add app/tmp/cache/.empty
% hg add app/tmp/logs/.empty
and make a clone, then the app/tmp/cache and app/tmp/logs directories will be created and new files in those directories will be ignored. I think that is what you want?
This is also useful for tracking something like $HOME since you would want to ignore most files by default and only track explicitly added files.
If I understand the question correctly you want to ignore file in tmp, but not files in certain directories in tmp. If that's right then I think you can do so using this:
syntax: regexp
^tmp/(?!(cache|logs|sessions|test))
That says ignore anything that starts with tmp, unless the next part is cache, log, sessions, test. For these files:
.
`-- tmp
|-- cache
| `-- afile
`-- tmpfile
here is the hg stat result:
$ hg stat
? .hgignore
? tmp/cache/afile
I will note, though, that Cake is probably telling you not to put those files into source control based ont heir being in a tmp directory. Are you sure they're not something htat your build system is supposed to create? Sessions in particular sound pretty transitory.
In my own checkouts (from SVN), when the site was deployed, the ./tmp/ directory needed to have some specific permissions.
I removed it from version control entirely, and my deployment script created the directories as required.

Categories