GitLab CI test differences between master and branch with Node - node.js

Currently I am trying to test the differences between master and a branch on GitLab CI.
var branch = require('git-branch'),
gitDiffTree = require('git-diff-tree'),
path = require('path');
var branch = process.env.CI_BUILD_REF_NAME || branch.sync();
var repoPath = path.resolve(process.env.REPO || (__dirname + '/../.git'));
{
repoPath: repoPath,
gitDiffTreeOptions: {
rev: 'master..' + branch
}
}
Here is the important bits of code that I'm using. This works great locally, but when ran on GitLab CI it says fatal: bad revision 'master.. branch' both times the branch variable was populated with the same value. Any advice how to get this to work? It previously used to do rev: HEAD which didn't work great because it only tested the most recent commit in the branch not all of them together.

I had a similar issue (bad revision 'master' when running git diff master -- . and similar commands), and got it working as follows:
run git fetch origin master (from the pipeline)
when referring to the master branch, use origin/master rather than master
I suppose the way gitlab fetches the repository contents does not cause master to be a valid branch name locally. I'm not familiar enough with the guts of git to pinpoint exactly why.

Related

GitLab refuses to merge branch

Working with GitLab.
On GitLab the branch was created 11-feature1. Some commits were done to it. Then a new branch was created 22-feature2. The second branch was successfully merged into the main branch and work continue on the first 11-feature1. Now I cannot merge that branch into main.
I am doing on the local:
$ git fetch origin
$ git rebase origin/main
### few conflicts stemmed from 22-feature2 is found and solved
$ git push
It looks good on the local side. But the remote (GitLab) still refuses to merge the branch 11-feature1 into the main. The message, "The source branch is 8 commits behind the target branch".
What to do?
I am now morally ready to completely abandon the branch 11-feature1 on GitLab and recreate it anew from the current main (which already has 22-feature2 in it). How to do it?

remote: Pushed to branch other than [main, master], skipping build [duplicate]

I have a project hosted on Heroku and it's gotten to the point where I want to make an alternate test server (so I can test Heroku workers without messing up production).
I have already set up my main Heroku remote running my trunk and a Heroku-dev remote on which I wish to run an alternate branch.
My problem is that since my alternate branch isn't master, Heroku won't build it.
$ git push heroku-dev test
counting objects ...
...
Pushed to non-master branch, skipping build.
To git#heroku.com:example-dev.git
* [new branch] test -> test
Switching this build to master is not an option at the moment. Obviously one option is to create a whole new git repo that's a clone of my test branch, but that doesn't sound very ideal.
You can push an alternative branch to Heroku using Git.
git push heroku-dev test:master
This pushes your local test branch to the remote's master branch (on Heroku).
Comment from #Brian Armstrong:
Worth noting also, when you're ready to go back to master you need to do
git push -f heroku master:master
In my case, the default or base branch was develop, so i used:
git push heroku develop:master
In case git push heroku-dev test:master doesn't work for you, try git push heroku test:master.
Remember the "test" in "test:master" is the name of the new branch you are on.
You will need to pull the remote branch first before you can push the non master branch.
Run following command in you local repository
git pull https://heroku:YOUR_HEROKU_API_KEY#git.heroku.com/YOUR_APP_NAME.git

Push gitlab repository code to Google source repository

I followed below article to push gitlab repository code to Google cloud source repository but I'm getting an error on this command
git push -f google master
error: src refspec master does not match any.
error: failed to push some refs to 'https://source.developers.google.com/p/project/r/test/'
Article followed:
https://medium.com/#bamnet/cloud-source-repositories-gitlab-2fdcf1a8e50c
Is there anything , I'm doing wrong 😜? Any thoughts as to how I can avoid this error message?
src refspec master does not match any
The issue is the date of the article you are following: Aug. 2018.
GitLab Runner has changed since then, more precisely in May 2019.
The problem is described in this thread from May 2019:
Since we are using refspec to clone/fetch the repository, we checkout a specific commit and not checking out a specific branch.
When the script does git push master, the branch is nowhere to be found so git doesn’t know what to push.
That was because of, on GitLab side, MR 1203:
Basically, GitLab CE/EE sends refspecs parameter to GitLab Runner gitlab-org/gitlab-foss app/presenters/ci/build_runner_presenter.rb: this parameter is to used in GitLab Runners for fetching branch/tag refs from remote repository.
This change was introduced because we wanted GitLab Rails side to leverage respecs in order for issue 7380 "Combined ref pipelines (source+target branch)" though, there should not be a big difference between git clone $URL or mkdir $REPO_DIR && git remote add origin $URL && git fetch +refs/heads/branch_name:refs/remotes/origin/branch_name.
In fact, the new behavior has already run on our development project
https://gitlab.com/gitlab-org/gitlab-ce/pipelines and has no issues so far.
Issue 4097 was opened at the time
Workaround
Use HEAD when you want to push this to another remote.
deploy:
stage: deploy
script:
- git remote add heroku https://heroku:$HEROKU_API_KEY#git.heroku.com/<project>.git
- git push -f heroku HEAD:master
So don't push master. Push HEAD.
The OP Adam uses another workaround and add:
before_script:
- git checkout master

How to pull from specific branch in git- understanding gap

I am using gitlab and really confused in few things. :
When we create new branch by git checkout -b test. Does it create copy of master or it creates copy of branch i am currently in?
For example: I am currently at branch dev, then i write command git checkout -b test. So it will be copy of dev, not masters?
Pull : when we write git pull , it pulls changes of current branch from remote branch of same name. Its used when more people are working on same project.
Example : I am at branch dev, i write git pull, it updates my local as of dev in remote. Now i created a new branch test, checkout test branch and do git pull. It gives me :There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
its because there is no test branch in remote ?
What command to be used if i want to pull from dev branch while my current branch is test? is it git pull --rebase dev test?
When we write git push, it pushes current branch to remote one.
example : i am on branch test, i add, commit and write git push. It simply pushes my branch test to remote with same name as test.
Can we push to specific branch like push test to dev?
What is difference in following considering i am at branch test:
git push
git push origin test
they both push to remote?
My requirement is : there is branch dev which is not master branch, i am supposed to work on this branch as starting and end point. Like, new branch should be copy of this and i am supposed to push to same branch.
Does it create copy of master or it creates copy of branch i am currently in?
It creates a new branch named test based on the current branch, whatever that might be, as a starting point.
What command to be used if i want to pull from dev branch while my current branch is test?
I believe you can pull any branch you wish into your current branch. E.g. if you were on branch test and wanted to pull dev you could just use:
git pull origin dev
Can we push to specific branch like push test to dev?
Yes, can specify both the local and remote branch names when pushing, e.g.
git push origin test:dev
1- When you do git checkout -b test it creates copy of your current branch(in this case 'dev').
2- git pull will only sync your changes between remote and local. If you upload the branch and try to pull, it does not work because your local and remote changes will be synchronized.
3- This could help you : Make an existing Git branch track a remote branch?.
If you want to work in a copy of a branch, you should do this:
git checkout <origin_branch> (master, dev, what u want )
git checkout -b <work_branch> (test, for example. This create a copy of your origin branch)
After this, you have a new branch 'test' in your local repository. If you want to push this branch on the repo:
git add .
git commit -m "Pushing new branch test"
git --set-upstream origin <your_new_branch>

Phabricator - arc land throws an Exception due to a wrong git call

I am playing around with phabricator and recently ran into an issue with arc land:
I created a test-repository, did a commit and got it into phabricator with arc diff. Worked as expected. The commit lives under a branch called "new_feature".
In phabricator the diff was rejected for testing purposes. After rejecting, I tried arc land:
$ ~/git/test> git branch
master
* new_feature
$ ~/git/test> arc land
Landing current branch 'new_feature'.
Switched to branch master. Updating branch...
Exception
Command 'git pull --ff-only' failed with error #1:
stdout:
stderr:
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "master"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
Next step the reviewer accepted the patch but arc land threw the same Exception.
Ideas?

Resources