I'm new to Git. i have everything worked before. but the problem came when i try to follow some tutorials regarding .gitignore not woking. Finally i used git clearcache but now i'm getting other error
I used :
git add .
git commit -m "testing gitignore"
git push origin arabic
Error :
You have both vendor/kartik-v/bootstrap-fileinput and vendor/kartik-v/bootstrap-fileinput/.github/CODE_OF_CONDUCT.md
You have both vendor/kartik-v/dependent-dropdown and vendor/kartik-v/dependent-dropdown/.github/CONTRIBUTING.md
You have both vendor/kartik-v/strength-meter and vendor/kartik-v/strength-meter/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-krajee-base and vendor/kartik-v/yii2-krajee-base/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-password and vendor/kartik-v/yii2-password/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-widget-datepicker and vendor/kartik-v/yii2-widget-datepicker/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-widget-depdrop and vendor/kartik-v/yii2-widget-depdrop/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-widget-fileinput and vendor/kartik-v/yii2-widget-fileinput/.github/CONTRIBUTING.md
You have both vendor/kartik-v/yii2-widget-select2 and vendor/kartik-v/yii2-widget-select2/.github/CODE_OF_CONDUCT.md
You have both vendor/kartik-v/yii2-widget-typeahead and vendor/kartik-v/yii2-widget-typeahead/.github/CONTRIBUTING.md
...
error: Error building trees
How i can fix this error ?
I'm unable to push to my repository now.
git clearcache is not a Git command. (Where did you get it?)
The error message suggests that whatever this git clearcache program is, it damaged Git's index. If you don't mind losing the effect of your git add ., you can re-build the index, then re-do the git add, using these basic shell commands:
rm .git/index
git reset
git add .
(this assumes you are at the top level of your repository, so that .git/index names Git's index file). Removing the file and running git reset rebuilds the index from the current commit, destroying the effect of all previous git add and/or git rm commands.
If git clearcache contains such commands, this will also undo its operations, but it looks like that may be necessary.
I had an issue where the directory on windows was in read-only mode
Click properties
Then if read-only is selected - de-select it and hit apply or ok. Next, you should close your IDE and then re-open it and try to make a new commit.
Related
unfortunately I can't use composer, due to low memory on the webspace. That's why I'm trying to push vendor/* to the git repository, to be able to pull the full project, including the dependencies.
In my .gitignore I'm forcing git to unignore the vendor files by !/vendor/*.
It works for most files, but not for /vendor/friendsofsymfony/jsrouting-bundle.
Content of /vendor/friendsofsymfony/jsrouting-bundle/.gitignore:
/phpunit.xml
/composer.lock
/composer.phar
/vendor/
/node_modules/
My repository is hosted at BitBucket. I don't know yet the meaning of the different folder-icon and the hashs next to it. If anyone knows, please comment.
Does anyone know how to force git to handle all the vendor files?
Thanks in advance!
Solutions
As the jsrouting-bundle is a git submodule, I chose this solution:
git submodule add git://github.com/FriendsOfSymfony/FOSJsRoutingBundle.git vendor/friendsofsymfony/jsrouting-bundle
Another way would be to use the deps file (not tested), source:
https://github.com/XKEYGmbH/ifresco-client/tree/master/vendor/friendsofsymfony/jsrouting-bundle/FOS/JsRoutingBundle/Resources/doc
The jsrouting-bundle folder is a Git submodule. A Git submodule is actually a reference to another Git repository. This is why you cannot add changes from it to your original Git repository.
I had to do this in the past, here is what I did:
php composer.phar selfupdate
php composer.phar update
In the vendor directory run sudo find . -type d -name .git | xargs rm -rf
Commit all modifications: git add -A .
With this, your vendor will be commit like the src directory, so no need to run composer install when deploying in your production environment. When wanting to update just repeat the process. But of course it isn't a good practice and you should do this only if you can't run composer on your production server.
When I run composer install --prefer-source or try to update this one particular bundle ( others work well ) I get this error:
Failed to download some-bundle from source: Failed to execute git checkout 'xx' -- && git reset --hard 'xx' --
error: The following untracked working tree files would be overwritten by checkout:
...
[ list of all files in repo on a branch that interests me ]
...
Please move or remove them before you can switch branches.
Aborting
I'm assuming I messed up something on the bundle repository, but have no idea what.
I clone brand new project repository
I try "composer install --prefer source" and still get that error.
What is interesting - the error occurs only on docker on MAC. On other pc with linux it works fine.
It looks like you have manually updated the sources in your vendor directory of this bundle.
If so, try to commit/push or reset them directly in the vendor directory before updating the package.
If not, it may relates to this issue: https://github.com/composer/composer/issues/2896
The author writes:
"This can be fixed in two ways:
when stashing, add --include-untracked flag which will stash newly added files as well.
when checking out, add --force flag which will overwrite files instead of aborting."
If nothing helps you can manually delete the vendor directory to force composer to newly install the package.
Edit Please take also a look at https://getcomposer.org/doc/03-cli.md#clear-cache, maybe composer has cached the git repository somewhere and cannot update it.
I've created my own site on my local computer and it works wonderfully. I'm having tons of fun developing with it. But when it came time to move it to my server and test I ran into issue.
I'm using the FOSUserBundle. Obviously being a Git of it's own, when I did a git commit and push, git ignored everything in vendor/friendsofsymfony/user-bundle. So when I cloned to my server, the folder came empty, and of course now my site doesn't work.
I want to do this the right way. So if it means destroying the git repo and doing it a different way, I'm ok with that.
So far I've tried.
Following the original install instructions for FOSUserBundle
Running the following:
composer update friendsofsymfony/user-bundle
composer install friendsofsymfony/user-bundle
Both return "nothing to update/install"
I've also tried clearing composer's cache between each command attempt.
rm -rf ~/.composer/cache
Answer is in the comments. Ignore vendor/ use composer to install the appropriate files.
also this Symfony project cloned with git vendors not installed
What it sounds like your trying to do is create a mywebsite parent repo within which you have a third party child repo that has the FOSUserBundle code. This uses git submodules and requires related submodule commands like git submodule init.
The ... directory is there, but empty. You must run two commands: git submodule init to initialize your local configuration file, and git submodule update to fetch all the data from that project and check out the appropriate commit listed in your superproject...
I don't know anything about composer. Here is how you could do it with git.
cd mywebsite
git init
git submodule add <url-to-FOSUserBundle-repo>
You should now have a directory structure like this:
mywebsite
.git
.gitmodules
FOSUserBunder
.git
See also http://git-scm.com/book/en/v2/Git-Tools-Submodules
The problem
I'm trying to build my application in Jenkins, and it is on a private repo on Github, also there's a private submodule.
I can clone the private repository in Jenkins by setting up it's credentials, but Jenkins can't clone the submodule, here's the output of a failed build:
Started by an SCM change
Building in workspace /var/lib/jenkins/jobs/Project/workspace
Fetching changes from the remote Git repository
Fetching upstream changes from git#github.com:user/repogit
using GIT_SSH to set credentials
Checking out Revision 9cc99b67cc676d0ea8ccd489a8327f5c6dbb8d7f (origin/branch)
[workspace] $ /bin/sh -xe /tmp/hudson2710403018107019432.sh
+ git submodule update --init --recursive
Initialized empty Git repository in /var/lib/jenkins/jobs/repository/submodule/.git/
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
Clone of 'git#github.com:user/submodule.git' into submodule path 'repository/submodule/' failed
Build step 'Execute shell' marked build as failure
Discard old builds...
#156 is removed because status FAILURE is not to be kept
Publishing Clover coverage report...
No Clover report will be published due to a Build Failure
Sending e-mails to:
Finished: FAILURE
Here's what I've tried to do in Jenkins
Tried to set the Additional behavior "Advanced sub-module behavior", with no success.
Tried to set up a new step before running the tests with phpunit:
git submodule update --init --recursive
Tried to set a git repository on the project of my submodule too, not just the main repository that is being tested, no luck too.
All of them causes the error that says that Jenkins can't find the repository of the submodule.
Any ideas of how can I solve this?
(The username, paths and repositories are correct, I've just changed them to post here)
Solved. In my credential I was using a direct SSH key (option "Enter directly"), instead of putting into a file.
I've just put the keys (public and private) in ~/.ssh, and changed my credentials to the option "From the Jenkins master ~/.ssh".
The problem was that the submodule wasn't using the credential that I've specified to the main repository, it was trying to use the default ssh key (.ssh/id_rsa).
Another solution is to pass -i my_key to the git submodule step (only need this if your key isn't in the default path (~/.ssh/id_rsa) )
Also don't forget to give the correct permissions to your keys, in my case I had to:
chown apache ~/.ssh/id_rsa*
chmod 700 ~/.ssh/id_rsa*
As a PHP developer I find myself working with Composer a lot. In the past it was on personal projects and such so I didn't have much problems with it, but now with Laravel 4 it's on project that require deploying and I'm in kind of a struggle to adapt my workflow.
All my projects are git repositories, thus per convention and because it's still quite buggy, like most developers I put the vendor directory in my .gitignore.
Now the problem is : I also use Git to deploy to the server, and by all logic the vendor directory is not uploaded as it's not tracked by the repository.
So my question is towards people that have worked with Composer and Git for longer than me : what is the best workflow to keep the server in sync ? How to track the vendor folder without really tracking it ?
I tried uploading it every time I update with Composer but some of my vendor folders are quite big and I can't manually upload 30Mb of files every time something updates.
I don't really know, how do you guys work it out ? I tried not ignoring the vendor folder but Git just messes it up, half are recognized as cloned repos and are just ignored anyway, etc.
UPDATE : Note that I'm on a shared host so I don't have access to the server's terminal.
The best way is to run composer install on the server after updating to the latest code. You should also make sure you commit your composer.lock file, which the server will then use to install (you should not run composer update on the server).
Capistrano (or Capifony if you are using Symfony2) is very useful for deployments with composer. You can trigger a deployment remotely and it will run a composer install in isolation so the site remains online until it has been deployed successfully. There are many other benefits such as retaining previous deployments and rolling back, copying old vendors before deployments, compiling assets etc. etc.
I'm working on something like this in the git post-receive hook on the server. This isn't tested and may be buggy, but you should get the idea.
#!/bin/bash
# get the updated composer.json
git checkout master -- composer.json
# only do this stuff if composer.json is different
# you could check this manually, or with git or cmp
cp composer.json tmp/composer.json
# may take a minute, but won't take the site down
(cd tmp; composer install --prefer-dist)
# this doesn't seem to be atomic
git checkout -f
# switch vendors over
# this isn't quite an atomic operation, but is very close
# you could probably do it with symlinks and "mv -Tf" to make it atomic
mv vendor vendor.old
mv tmp/vendor vendor
rm -r tmp vendor.old
Ideally all of the deploy (i.e. in this case the git checkout and the composer install) except one single mv would happen in isolation, outside of www. This doesn't work if you have untracked files (eg CMS uploads) in your working tree and rely on PHP's __FILE__ not resolving symlinks (due to this PHP bug).
This is an old question but in case anybody is looking a solution:
I slightly modify the #dave1010 answer to use git pull instead of git checkout--force
#!/bin/bash
# get only composer files
git fetch
git checkout origin/master -- composer.json
git checkout origin/master -- composer.lock
# make sure tmp is empty
rm -rf tmp
mkdir tmp
# copy the composer files to tmp
cp -r vendor tmp/vendor
cp composer.json tmp/composer.json
cp composer.lock tmp/composer.lock
# may take a minute, but won't take the site down
(cd tmp; composer install --no-scripts --verbose; cd ..)
# switch vendors over
rm -rf vendor_old
mv vendor vendor_old
mv tmp/vendor vendor
# update your code
git pull
# run again composer install. This time will print 'Nothing to install or update'
# but will execute pre/post scripts & generate autoload files
composer install --optimize-autoloader
There is maybe a better solution using capistrano/composer. But I like mine better.
You can use something like jenkins to ftp your files over this way you can direct jenkins to run composer install on the jenkins server and then ftp the files over.
This also allows you to ignore the vendor folder.
It does require a build server to be made and you would need to be able to execute commands vs the build server
The key is your composer.lock file. The composer.lock keeps track of exactly what packages (and versions) you have installed. When you deploy, send your composer.lock file up to the production server as well, and simply do a composer update. All the exact same package versions will be installed. With deployment software like Capistrano or Flightplan you can make the composer update step part of the process so it happens automatically.