Why does Travis CI edit my files? - ruby-on-rails

I'm new to Travis CI and I simply want to understand why and what is going on here. I've followed the instructions for setup in their documentation to the best of my ability. What I've got is:
My Rails code on Github
Travis CI that build my repo as soon as it is pushed to the github branch master.
A Heroku app to where Travis CI deploys the code if the build is successful.
What I can't grasp is why I get this when the build is finished:
HEAD detached from 2a3b308
Changes not staged for commit:
.......
modified: script/travis.sh
Untracked files:
(use "git add <file>..." to include in what will be committed)
vendor/bundle/
no changes added to commit (use "git add" and/or "git commit -a")
I do a before_install: - chmod +x script/travis.sh in my .travis.yml and I get chmod +x script/travis.sh in my build log. I have git version 2.7.4
Why is my script/travis.sh edited? Should I add those changes or is something wrong in my setup? In the script/travis.sh I've got some minor commands to be executed before the build, setting up my Github identity and such.
Why is this folder vendor/bundle/ added?

You would need to add a git diff step to see the nature of the change, but check your travis logs: if you see
chmod a+x travis.sh
That means your original travis.sh script was not added as executable.
In your repo, do a (with Git 2.9.1+):
git add --chmod=+x script/travis.sh
git commit -m "Make travis.sh executable"
git push
Then check again if travis still displays your file as modified after a build.
Regarding vendor/bundle/, it is not "added", simply generated and untracked, which means your repo is not modified.
See Travis/Cache Bundle
On Ruby and Objective-C projects, installing dependencies via Bundler can make up a large portion of the build duration. Caching the bundle between builds drastically reduces the time a build takes to run.
If you have custom Bundler arguments, and these include the --path option, Travis CI will use that path. If --path is missing but --deployment is present, it will use vendor/bundle.

Related

How to ignore untracked files

Untracked files:
(use "git add ..." to include in what will be committed)
META-INF/
classes/
repository/
sample-2.0.9-SNAPSHOT-mule-application.jar
temp/
test-classes/
the above are untracked files and i want jar file and ignore other file.
basically i am doing is trying to push jar files from jenkins to bitbucket.
and i facing issue is when i do changes in that particular pom file and push again i am facing this issue. although i tried adding .gitignore file but i am unable to over come this problem.
It will be helpful if you help me with this error
and the jenkins file code looks like:
stage('bitbucket deploy') {
steps {
script{
GIT_CREDS = credentials('bitbucket-server-cred')
sh '''
echo "${WORKSPACE}"
cd ${WORKSPACE}/target
git init
git config --global user.name "admin"
git status
git remote add origin http://***:*****#**:***:**:***:7990/scm/or/lla-esb-artifactory.git
git remote -v
git pull origin master --allow-unrelated-histories
git add -f *.jar
git status
git commit -a -m "push into bitbucket"
git push origin master
'''
}
Thanks in advance
It seems like you are missing the step of actually creating the JAR file. Untracked files are not staged or committed, and it will not be pushed into the git repo. When you perform the git pull, it pulls the master branch from your remote. But since you are not tracking the JAR file, it means that it is not being uploaded to git to begin with.
The ideal thing to do here would be to build the JAR file after pulling the repo using mvn package or whatever action you have in your POM to build the JAR file. Remember to clean your workspace when the build stage is complete.
Alternatively, since it seems that all you are doing in this build step is including the JAR file in the repo, you can run git add *.jar to add the JAR file to the repo where you have it as an untracked file, and remove this build step, since the file will be in the repo to begin with.

git "expected shallow list" error when shallow had tested as true

I have a repo that, when tested on Travis, consistently gives an error like:
$ if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
fatal: git fetch-pack: expected shallow list
The command "if [[ -a .git/shallow ]]; then git fetch --unshallow; fi" failed and exited with 128 during .
Your build has been stopped.
You can see an example here, although it's possible that link requires authorization.
What I find strange about this that it seems the git fetch --unshallow should run only if it's already determined that it is shallow. I should add that I've used this construct in many other repositories and never had a problem.
On my local machine, the contents of .git are:
myrepo.git$ ls -a
. branches config FETCH_HEAD HEAD index logs ORIG_HEAD
.. COMMIT_EDITMSG description gitk.cache hooks info objects refs
I am not hip to the internals of Git, nor do I really understand what git fetch --unshallow is actually supposed to do, but one possibility: check which version of git you have available to your Travis test runners.
I see the same fatal: git fetch-pack: expected shallow list error message with a GitLab CI/CD shell runner on CentOS 7 VMs. CentOS 7 only has Git 1.8.something in the official repos.
This blog post is where I initially became aware of this error message being related to an old version of Git. That post suggests upgrading the OS-default version of git with third-party repos, which I didn't want to do.
What I ended up doing instead, as advised here, was setting:
variables:
GIT_STRATEGY: clone
in the .gitlab-ci.yml. This is, of course, a GitLab-specific thing, but I'm pretty positive Travis gives you some option for setting environment variables for your test environment.
See also:
gitlab runner doesn`t work on a specific project (Ryan Daniels' answer)

git checkout master command gives error that a file would be overwritten

I just made tried to do git checkout master and I got this error:
macoss-MacBook-Pro-10:Marketing owner12$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
Marketing.xcodeproj/project.xcworkspace/xcuserdata/owner12.xcuserdatad/UserInterfaceState.xcuserstate
Please move or remove them before you can switch branches.
Aborting
but I am not sure how to handle this situation. I don't mind having this file overwritten by what is in the repo. What is the correct way for me to proceed here?
Thanks!
You have files that are not being tracked. Either
rm untracked.file1 untracked.file2
or
git add . && git commit -m "adding new previously untracked files that serve a purpose"
if you're having permission issues:
git add --ignore-errors .
Either delete the file if you don't care about it or stash it if you think you will need it in the future. Or simply rename.
Commit the files you want to keep and then do a git clean to remove the extra files you don't want to keep. This article on the git ready website describes it very well.
If you just want to get rid of one or two files in your working directory then you can do a dry run first and see which files would be cleaned up using:
git clean -n
And then when you are sure do this:
git clean -f
git clean has a -d switch if you want to clean up directories as well. And you can use that together with the other switches, so this is what I would normally use (and then after the dry run change -n to -f):
git clean -n -d
Then after your git clean, use:
git status
to make sure that you have no untracked files or uncommitted changes. And lastly switch to master with:
git checkout master

What does the git error mean "pathspec did not match any file(s)"

In a Rails app I realised I had committed a sensitive file config/credentials.yml to the git repo.
In an effort to tidy things up I followed the advice on GitHub and ran
git filter-branch --index-filter 'git rm --cached --ignore-unmatch config/credentials.yml' --prune-empty --tag-name-filter cat -- --all
and then added to gitignore
echo "config/credentials.yml" >> .gitignore
When I try to commit these changes
git add .gitignore
git commit -m "ignored credentials.yml"
I'm getting a message
error: pathspec 'adds credentials.yml to gitignore' did not match any file(s) known to git.
How can I fix this error? Or, how can I undo my changes and safely revert to the git history on my remote?
I think you might've forgotten the step
$ git add .gitignore
before trying to commit, or then you mistyped, when you shoud've given
$ git commit -m "Add credentials.yml to .gitignore"
Process advised is highly dangerous [for the repo contents], so one must be really careful to follow all the steps in detail.
Just give a file path while adding file to git add command, it works for me
$ git add mainFolder/.../file.extension
Note: mainFolder would be the folder inside your repo

How to install a plugin from github?

I have tryed to run this code in my console:
script/plugin install git://github.com/apotonick/cells.git
...but i only get an empty folder named "cells" in my "vendor/plugins" dir.
What's wrong?
Check you Git version.
This may be related with you gitconfig file, as described in this thread
The reason is that it appears rails-2.3.5/lib/commands/plugin.rb is trying use git pull to grab the plugin code (see the install_using_git method), which doesn't work right.
Example:
script/plugin install git://github.com/fesplugas/typus.git
mkdir vendor/plugins/typus
cd vendor/plugins/typus
git init
git pull --depth 1 git://github.com/fesplugas/typus.git
That last line exits 1, but that error is being masked by the install_using_git method, and the directory is just rm -rf'ed.
I tracked this down to a conflict with ~/.gitconfig. If I remove these lines it works:
[branch "master"]
remote = origin
merge = refs/heads/master
It appears a naked git pull has problems with these settings.
Actually, the problem would be here because of a global git config file (in your homedir: '~/.gitconfig'), defining a master which may be incompatible with the master expected by the git pull within that specific Git repo.

Resources