Capistrano uploads the .git directory - php

I am using git with capistrano.
I initialized my project inside my folder on my local machine as such:
git init
I then pushed the project the server directory
I then called cap deploy
The deploy works, except that it uploads the local .git folder structure, as well as my .gitignore and Capfile to a publicly accessible folder.
Here's my gitignore file:
.DS_Store
uploads/**/*
Capfile
.gitignore
.git/**/*
This doesn't seem to do the trick. Any help?
Thanks!
Edit: updated .gitignore file:
Changed deployment strategy to export:
set :deploy_via, :export
This works for ignoring the .git folder, but the contents of my .gitignore file seen below are still not taken into account
.DS_Store
includes/php/config.php
/uploads
Capfile
.git
EDIT 2 (Solution): Edit 1 in combination with the following did the trick.
Files that were already added prior to being listed in the .gitignore file would constantly be uploaded. Say I had the following .gitignore file.
.DS_Store
includes/php/config.php
Then I ran the following commands:
git add .
git commit -a -m 'some commit'
Then I decided to add to my .gitignore file so it now looks like this:
.DS_Store
includes/php/config.php
Capfile
Then again, I ran:
git add .
git commit -a -m 'another commit'
Now I'd see that .DS_Store and includes/php/config.php have not been uploaded, but that the Capfile has... This is what happened to me in my original question.
The reason: I think the .gitignore file is taken into account only when adding (i.e. git add .). If I already added files, then put them in the .gitignore file, they would have already been added to the project. I'd need to use the git rm command to remove them.
I just started anew with a new .git repo and that solved the problem, but you don't have to - you can just remove whatever files you already added but now want to ignore with the git rm command.
I selected the answer that helped me get to this conclusion as the right one, though the complete solution was just detailed above.

What is your deploy strategy?
Do you have Capistrano setup to exclude the .git file?
if you are using set :deploy_via, :copy then make sure to add the following:
set :copy_exclude, [".git/*", ".svn/*", ".DS_Store"]
Otherwise use set :deploy_via, :export which should ignore your source control folders
http://www.capify.org/index.php/Understanding_Deployment_Strategies

Looking at a similar question, it appears you don't need the wild card selectors and can just have:
uploads/
You need to deploy via :git in Capistrano and do an export. It's essentially a git clone and then just deletes the .git directory afterwards.
Your problem isn't much to do with Cap really. Make sure your .gitignore file is working correctly.

Related

Cannot mkdir with git clone

Once I clone my repo, the folders don't have write access, and so my PHP code cannot use mkdir() to make a folder if it needs to.
I get this error:
mkdir(): Permission denied
Why is this? In my repo I have a pages folder, which has the following permissions after I git clone it to my /var/www/html folder.
drwxr-xr-x 4 me me 4.0K Jun 9 18:30 pages
Is this set in the repo itself? Or is there some command I can add to git clone that will allow me to fix this?
The only file permission that is tracked and handled by Git is the executable bit. Everything else is not tracked and not controlled by Git. This is one of the arguments against using Git as a deployment tool which it is not. You can find some hints on how you can utilize Git to make a deployment strategy at http://gitolite.com/deploy.html. The permssions of the files after cloning are simply the default on your linux system. You can change this in your linux environment to be something different.

composer vendor/bin files not being detected on Ubuntu Terminal

Yesterday I've just installed Laravel with Behat on my VM Ubuntu 15.10.
Everything works fine, running the command $ vendor/bin/behat --init successfully created the features/ folder
but today something is weird, when running the $ vendor/bin/behat its saying vendor/bin/behat: line 1: ../behat/behat/bin/behat: No such file or directory
What's inside the vendor/bin/behat file?
This first single line ../behat/behat/bin/behat
accessing the actual location works $ vendor/behat/behat/bin/behat which basically means the file DOES exists
Please note that the issue is the same for the files in vendor/bin like doctrine phpspec etc..
You're having relative path problems. If your current directory contains vendor/ and you execute vendor/bin/behat, then ../behat/behat/bin/behat doesn't exist because it's going one directory up from your current directory, not vendor/bin/. For example:
$ cd $HOME/project
$ vendor/bin/behat
vendor/bin/behat: line 1: ../behat/behat/bin/behat: No such file or directory
That relative path becomes $HOME/project/behat/behat/bin/behat and not $HOME/project/vendor/behat/behat/bin/behat (note vendor present in the second path)
You need to be inside vendor/bin/ when executing behat:
$ cd $HOME/project/vendor/bin
$ behat
...
However, I don't see this being an issue with the latest behat install, line #1 is a well formed shebang. I think you might want to destroy your vendor install, update composer, etc, and reinstall Behat. Those files should not start with relative paths.
EDIT:
According to the composer docs, it creates symlinks to package binaries, as seen in the source code. You can verify this by running ls -l vendor/bin (all symlinks will have a -> pointing to their destination path). It would seem your original php composer.phar require ... was corrupt from the beginning.

Git::Windows: pull case sensitive files from remote repo

In my remote repository I have files,
example,
-account.php
-Account.php
To see how exactly my repository looks like,
I am now using windows git bash to clone/pull the files from remote repo.
While doing that only
-account.php
gets cloned, while
-Account.php
is being ignored!
How do I get both the files,
-account.php
-Account.php
into my local repository, so that I can delete them and make a clean commit of files with only one naming convention and eliminate the mistake I have done?
Since git is a unix based it simply a case sensitive software.
If you have committed a case sensitive files you will need to rename them. Using the git mv command will tell git to rename the file while keeping all the history of the file
# "move" the file from the old name to the new name
git mv -f File file
# Add the file to the staging area
git add .
# commit your changes
git commit -m "renamed file..."
Git has a configuration setting core.ignorecase.
To tell Git to be case-senstive, simply set this setting to false:
git config core.ignorecase false
Documentation
From the git config documentation:
core.ignorecase
If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT.
For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile.
The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Uploading Single image in a git directory

I have created my project repository on git. Its a web development project. I want to upload a file to it.
For other kind of files (.txt, .php, .html, etc.) I know I can create a new file by clicking on + button and then copying my file's content there.
How can I upload an image to the specific directory (./img in my case). I have searched a lot but didn't got any suitable answer.
You can use this method if You are a beginner.
You can add files using git add, example git add README, git add /*, or even git add *
Then use git commit -m "" to commit files
Finally git push -u origin master to push files.
When you make modifications run git status which gives you the list of files modified, add them using git add * for everything or you can specify each file individually, then git commit -m and finally, git push -u origin master
Example - say you created a file README, running git status gives you
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
Source :: How do I add files and folders into github repos?

Git - Exclude a config file from post-receive checkout

I have a git project that I'm working on locally. It's a PHP project with a config file that stores MySQL database connection information. My local MySQL settings are different from the remote settings.
On my remote, I have a post-receive hook that will checkout the files to a folder on the server:
#!/bin/sh
GIT_WORK_TREE="../demo" git checkout -f
chmod +x hooks/post-receive
How can I tell this checkout not to include (overwrite the config file), since it will replace the remote config file with my local one? I've tried adding my local config file to the .gitignore, but that didn't seem to do it.
Any idea how to exclude the config file from the checkout?
The proper solution is not committing your config.php (or whatever its name is) at all but rather putting it in the .gitignore and committing config.php.example instead.
So, simply remove the config file from the repository, rename it on your remote machine, pull so you have the newest commit (which would remove the file) and then move it back.
You can try this
Running command:
git rm -r --cached .
This removes everything from the index, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"

Categories