Using Git with your CakePHP Project - php

I use git as my primary version control system, and have recently started using git on my CakePHP projects. This is my current .gitignore file:
app/tmp
vendors/
As used in the cakephp git repo, but this causes a bit more work for me when deploying the project to a server, because I have to go in and create all the app/tmp/ sub-directories by hand before they will work correctly. Is there a way to set it up to ignore the contents on these folders, but to still have them under git control so they appear when I clone the repo into the hoted directory?
I also have been having an issue with my git index being reset while I am working on it, which is causing me to have to do a lot more commits than should be necessary, any ideas on that also?

Git stores only files, not directories, so you can for example add a hidden file into that directory and commit it.
Remove app/tmp/ from .gitignore
touch app/tmp/.keep
git add app/tmp/.keep
git commit
Add app/tmp/ to .gitignore

As mentioned git only stores files, not directories. By default cake's .gitignore file ignores all contents in the tmp folder to prevent tmp files being added to your repository.
You can (and should) however do this after you create a project:
cd /my/app
git add -f tmp
which will do this:
$ git status
# On branch master
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: tmp/cache/models/empty
# new file: tmp/cache/persistent/empty
# new file: tmp/cache/views/empty
# new file: tmp/logs/empty
# new file: tmp/sessions/empty
# new file: tmp/tests/empty
As such your tmp folder structure is ready to be committed, but all other files in your tmp dir will (continue to) be ignored.

My .gitignore file.
tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php
webroot/files/
webroot/img/photos/
!empty
.DS_Store
If you'll notice I have !empty which saves me from creating .keep files all over which is so SVN ago. Lastly you'll also see that I use this config for both cakePHP 1.x and 2.x projects noted by the [Cc]. I have some folders setup that I store user files in so I always ignore them as well. Finally the .DS_Store ignores my MAC created thumbnail views for my project.

Related

Symfony 5 deployment issues (showing empty page)

This is my first deployment in Symfony 5 and I've been struggling a couple days with deployment because my website is showing a blank page.
I'm using Infinity Free Web Hosting with:
PHP Version 7.3.6
Apache
My website doesn't have a db.
So before I start to upload files with FileZilla, I run this commands:
SET APP_ENV=prod
composer install --no-dev --optimize-autoloader
composer dump-autoload --optimize --no-dev --classmap-authoritative
My folder structure goes like this
htdocs
\css
\downloads
\images
\scripts
.env.local
.htaccess
index.php
\symfony
\bin
\config
\src
\templates
\translations
\vendor
\var
composer.json
And modified index.php with new path:
require dirname(__DIR__).'symfony/vendor/autoload.php';
The issue is that the page is showing completely blank (not even an error). What is my mistake?
I've been following instructions with this tutorial, create a "symfony" folder with bin, config, src, templates and vendor, and I copied my "public" folder content to /htdocs folder.
Hosting provider doesn't allow me to upload content at the server root folder.
Thanks in advance.
You missing a / on your require :
require dirname(__DIR__).'/symfony/vendor/autoload.php';
Maybe use dev environment for debugging your application.
You have a .env.local : are you sure is necessary and correctly read ? (symfony/dotenv is a devDependency by default)
And I think is not a good practice to have your symfony folder and index.php on same directory because it can expose your source code and sensitive data. Maybe use htaccess to expose only symfony public directory.

Unable to add all the files to git downloaded via composer

I am using imgix module in drupal which is dependent on composer. When I run command drush composer-manage install, I can see imgix-php (a library of imgix) is downloaded in vendor directory. I have setup everything correctly and it works well in my localhost. Now I want to push them into github. I can see none of file of imgix-php is added in git and it is emty in github. Then I have see there is a file .gitignore in imgix-php where vendor is written. However, I have commented it out. But unable to add any files of imgix-php. If I commented out the line vendor of .gitignore and check the status, it shows me as:
On branch staging
Your branch is up-to-date with 'origin/staging'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: sites/all/vendor/imgix/imgix-php (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
Could tell me someone why I can't add them.
Have you actually added the imgix-php files after you commented the .gitignore file, using
git add /path/to/folder/*
or
git add --all /path/to/folder
?

Overwriting files on local disk from github (using Laravel framework)

I'm trying do to the following:
1) Create a new laravel project using:
sudo composer create-project laravel/laravel /var/www/html/laravel5`
2) Overwrite only the different files from github. I want to keep the following files and folders unchanged:
.env
.env.example
.gitattributes
.gitignore
vendor/
Clone from github is not working because the folder is not empty.
The only workaround that I found is:
create a new project
copy the files and folders that I want to another folder
clone the project from github
copy the files back to the folder
I'm using Xubuntu, Laravel 5.0 and Github.
Thanks in advance.
You should be able to do this via an all-git method rather than copy/paste from another directory. (I'm not sure why your workaround is a bad solution, though.)
The basic plan is:
Create a repository.
Checkout some bogus branch that you won't keep around.
Add the directories you want to keep to the index and commit them.
Force a checkout to the branch you want. It probably will need forcing because of the other things you didn't just commit.
Apply the patch of the recently created commit to your working directory.
And in commands:
cd /path/to/repo
git init
git branch temp-branch
git add .env && git add .env.example && git add .gitattributes && git add .gitignore && git add vendor/
git commit -m "Sustain Local Changes"
git remote add origin https://github.com/owner/repo
git fetch
git checkout -f master # Should detect origin/master. If it doesn't, just set a branch up manually. Replace master if that's not the branch you want.
git merge --no-commit --no-ff temp-branch
Personally, I find this a lot more ugly than your workaround.

Why won't Git add/commit files when node_modules folder isn't ignored in .gitignore?

The question
I can't add or commit with git when node_modules isn't ignored in the .gitignore file. When it is, everything works just fine.
Why is this? I do not understand and it bugs me. Is it ok not to upload the node_modules folder? I push and deploy to Amazon Web Services with their eb cli tool.
Details
I'm new to web devolopment. I use laravel 5 with homestead, and currently try to move my app from heroku to Amazon Web Services.
When my .gitignore look like this:
/vendor
.env
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
It says "no changes added to commit" when I run
git add -A
and then
git commit -m "Test Message"
but there is. I added a test change to my about file.
But then if I ignore the node_modules folder like this:
/vendor
/node_modules
.env
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
and add and commit again, the change is registered as it should.
I believe the node_modules folder should be ignored as the github repo for Laravel has it listed in the .gitignore. Most of that should be added by npm anyways.
You can view it here

how to include vendor and other ignored directories/files in jenkins builds using GIT

i have a git repository where i have the following directory structure:
src/
vendor/
app/
public/
vendor/ contains as you'd expect, 3rd party libraries (symfony, etc) which i do not want included as part of the repository. as a result of this, in my jenkins template which i have set up as 'Poll SCM' so builds can be automated from commits, it does not copy over the vendor/ directory into the workspace build, and so test fail because the library is not included in part of the build.
i came across git submodules whilst doing some troubleshooting into this, but im not sure they are the answer. as i'm sure im not the only one to use jenkins with the git plugin to create builds, and with ignored files/directories how can i go about getting the vendor/ directory and files across without putting them into the git repository?
managed to find a workaround after digging in the Jenkins Job Configure screen - under the 'Build' section, aswell as 'Invoke Ant' there was an option to 'execute shell' ... i put the line 'composer install' in there and that successfully installs everything needed from the vendor/ folder before running ant and then the unit tests.

Categories