Github Actions Env Variable - Lefthook - environment-variables

So migrating from TravisCI to Github actions, I had a lefthook.yml file that git diff --name-only --diff-filter=AM HEAD origin/${TRAVIS_BRANCH}
Now being on Github actions, what env variable would I replace that with? Because origin/main, origin/* all doesn't work

Related

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.

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: Compare 2 branches in different remotes

I'm using Heroku Pipleines to deploy from a staging environment to production, and want to write a script which compares the two remote repos to see if there are any pending migrations. So I need something along the lines of:
git diff staging/master..production/master
with a filter to check the db/migrate directory.
Any ideas? Thanks.
The man page says the syntax is:
git diff [options] <commit> <commit> [--] [<path>...]
In your case this means:
git diff staging/master production/master -- db/migrate

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

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