How do I skip cloning and checking out from my repo in Travis CI? - travis-ci

Is there a way to specify in my .travis.yml for a repo repo_x that I do not want to clone that repo or check out any of its branches?
For example, if I have a Homebrew Tap I'm testing, I will be acquiring the components I want to test with brew tap and brew install and will have no need of any of the contents of the Tap's repo.

Interesting question and idea!
In looking at the .travis.yml parser code, there seems to be 3 (possibly 4 options):
depth
submodules
strategy
quiet (defined elsewhere, mentioned in docs)
git clone --depth=0 is invalid because git returns fatal: depth 0 is not a positive number
The best strategy for an efficient "minimal clone time/impact" for travis may be the following:
git:
quiet: true
depth = 1
submodules = false

Related

"Fatal: Needed a single revision" appears when bundle install

I git pull a project to my local side (MacOS), and I need to perform bundle install before running rails server. However, during this process, when one of the Fetchings was executed, the following error occurred.
I have tried to add branch 'main', but it didn't work.
Fetching http://github.com/RubyMoney/eu_central_bank.git
fatal: Needed a single revision
Revision master does not exist in the repository http://github.com/RubyMoney/eu_central_bank.git. Maybe you misspelled it?
I ran into this issue in an internal project. We did a workaround so I can't test, but I just traced some bundler source code. The code for ref:, tag:, and branch: is all the same. They are treated as synonyms.
This failed:
gem 'my-gem', :git => "https://my-server/my-gem.git", :tag => 'v0.1.0'
The error looked like this...
Fetching https://my-server/my-gem.git
fatal: Needed a single revision
Git error: command `git rev-parse --verify v0.1.0` in directory
We discovered that by default branches are pulled by the git clone, but not all tags. Tags that are not on a branch don't always get pulled. To workaround we just created a branch that contained the tag in question.
In the future it might work if you specify the reference like this...
gem 'my-gem', :git => "https://my-server/my-gem.git", :tag => 'refs/tags/v0.1.0'
If you look at the code I link to in github, you see that triggers the value extra_ref to be set, which triggers an additional git fetch to get that ref specifically.
https://github.com/rubygems/rubygems/blob/6a655a698e952f897d0d014fc11bae4b608528ce/bundler/lib/bundler/source/git/git_proxy.rb#L88-L104
It does a two step process. First it does something like this... (The ./foo is a target directory. It can be anything.)
git clone --bare --no-hardlinks --quiet -- https://my-server/my-gem.git ./foo
Then it does this...
git --git-dir=./foo fetch --force --quiet --tags -- https://my-server/my-gem.git refs/heads/*:refs/heads/* refs/tags/v0.1.0:refs/tags/v0.1.0
which will explicitly get the tag in question.
This second step is done whenever the reference begins with ref/.

Why does Travis CI edit my files?

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.

Why do I get an Large File Warning from Github for a file that i have listed in gitignore?

Without really thinking about it, I've been committing and then pushing to my Github repository the images I am using in development.
After discovering that this was causing issues that prevented me from pushing my project to my branch, I searched for a solution to remove those images from my repository then add those images to my gitignore file.
I found several solutions: StackOverflow, this blog, git and a few others. They all seemed to be pushing me the same way:
git rm --cached -r /public/uploads/image/file/**
I've run a few variations of this code, like dropping **, file/**, --cached, and image/file/**, but it doesn't change the fact that I can still see the files on my GitHub branch.
Also I've added this to my gitignore file: /public/uploads/image/file/**
But when I push to the repository branch I get this info telling me why I can't push to Github:
I started from git add . for context.
ruby 2.3.3-p222
╳ project_name categories ◆ git add .
ruby 2.3.3-p222
╳ project_name categories ◆ git commit -m "trying to get a commit in after purging development environment image data"
[categories 8c13b0a] trying to get a commit in after purging development environment image data
1 file changed, 1 insertion(+), 3 deletions(-)
ruby 2.3.3-p222
╳ project_name categories git push origin categories
Counting objects: 3840, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3664/3664), done.
Writing objects: 100% (3672/3672), 163.83 MiB | 3.98 MiB/s, done.
Total 3672 (delta 1242), reused 0 (delta 0)
remote: Resolving deltas: 100% (1242/1242), completed with 57 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 85ba931580b369a222fcf5903416f84e
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File public/uploads/image/file/30/show_55MiEk4_-_Imgur.gif is 119.49 MB; this exceeds GitHub's file size limit of 100.00 MB
To git#github.com:Lenocam/project_name.git
! [remote rejected] categories -> categories (pre-receive hook declined)
error: failed to push some refs to 'git#github.com:Lenocam/project_name.git'
So, now I'm confused because doesn't adding /public/uploads/image/file/** to my gitignore file tell git to ignore the folder and the files inside of it? Why does the file continue to be pushed to my repository?
It seems to me I've asked git/Github to get rid of those old files(through the terminal command) and completely forget they ever existed so they will stop asking me about them(through gitignore).
I assume I've done something out of order or otherwise incorrectly. Any assistance you're able to give me will be appreciated.
.gitignore doesn't really ignore files
In Git, a file is tracked if and only if it is in the index.1
If a file is in the index and you make a new commit, that file goes into the commit. This happens regardless of whether the file name is in .gitignore.
Once a file is in a commit, it is in that commit forever. The only way to avoid it is to stop using that commit entirely.
What .gitignore does is to make Git stop whining. For each file you have in the work-tree,2 but not in the index, Git complains: "hey, this file is in the work-tree but not in the index! Maybe you should add it!" But some files that do belong in the work-tree do not belong in any commit, and hence should never go into the index.
Putting the file—or a matching glob pattern, e.g., anything using * or **—into .gitignore tells Git: "Don't complain, and also, if it's not already in the index, don't automatically add it either with git add -A etc." But it doesn't take the file out of the index, and it literally can't take the file out of any existing commits that have it.
To remove a file from the index, without removing it from the work-tree, use git rm --cached.3
You not only have (or had) the file in the index—which means that git add -A updates it in the index—you also have it in some commit you have not yet pushed. So removing it from the index is not sufficient. You must abandon each commit that contains the large file.
To do so, you probably want to use git rebase -i to copy that commit (or those commits) to a new and improved version, where the improvement is simply "do not include the file in the commit".
See also Can't push to GitHub because of large file which I already deleted.
1The index is where you build the next commit. It is not a commit itself, but when you run git commit, Git packages up the index contents to make the new commit.
2The work-tree is simply the place where you work on your files, since the form of files inside Git's index and Git's commits is unusable for normal work.
3Note that you should not let the shell expand any glob patterns you are using in your .gitignore files, for two reasons. First, the shell expansion may not match that done by Git. Specifically, not all shells expand ** at all, and those that do, do not always do it the same way. Second, the work-tree contents may differ in significant ways from the index contents: for instance, if you have public/uploads/image/file/1 in the work-tree but not in the index, the shell, which looks at the work-tree, may include that in its glob expansion, while Git, which looks only at Git's index when doing git rm, would not put that in the list of files to remove—and as soon as Git finds one file it can't remove from the index, it stops removing other files.
git rm --cached -r /public/uploads/image/file/**
You have added the file to .gitignore after it was already added to git.
Look like your ignore pattern doesnot match the file pattern
public/uploads/image/file/30/show_55MiEk4_-_Imgur.gif
Add the following pattern to the .gitignore
/public/uploads/image/file/**/**
You first have to remove it and than push it again.
git rm --cached <file>
git commit -m "Message"
git push ....

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)

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