I am facing this issue during try to deploy script with gitlab ci/cd:
Initialized empty Git repository in C:/builds/Tri.BuiV/test-gitlab-cicd/.git/
fatal: detected dubious ownership in repository at 'C:/builds/Tri.BuiV/test-gitlab-cicd'
'C:/builds/Tri.BuiV/test-gitlab-cicd' is owned by:
'S-1-5-83-1-1989435290-1148643240-1709935003-3943614564'
but the current user is:
'S-1-5-93-2-1'
To add an exception for this directory, call:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
I tried:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
But the same error, why?
I tried:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
But get the same issue.
If the error persist, it probably means your git config --global (which impacts %USERPROFILE%\.gitconfig) does not use the same account as the one running your GitLab CICD.
If GitLab runs with a different account, it might try to access folder initially created by you.
The GitLab pipeline itself would need to include
git config --global --add safe.directory $CI_PROJECT_DIR
This i what is being automatically added for GitLab 15.8 in MR 3538.
I am trying to checkout a branch from our organization github repo using Carthage but it fails with error message
Cartfile
git "ssh://git#github.com:orginaztion/repo.git" "branch"
In command line
carthage checkout --use-submodules --use-ssh
Error message:
A shell task (/usr/bin/env git fetch --prune --quiet ssh://git#github.com/orginaztion/repo.git refs/tags/*:refs/tags/* +refs/heads/*:refs/heads/* (launched in /var/root/Library/Caches/org.carthage.CarthageKit/dependencies/repo)) failed with exit code 1
Am I doing something wrong here ?
On the install step, Travis CI clones the repo, which looks similar to this:
git clone --depth=50 --branch=master https://github.com/user/repo.git user/repo
How can I customize / override this?
Background: I am using tag based deploys. The way Travis checks out tagged builds (--branch=<tagname>), the git repository is in a detached state without access to branches. However, for deployment I need to know on which branch I am. My solution is to do a "normal" clone and then switch to the tagged commit.
You can clone the repository again in the install step. That way you clone the repository twice, but it seems to work.
# .travis.yml
install:
- git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG
- cd $TRAVIS_REPO_SLUG
- git checkout -qf $TRAVIS_COMMIT
Per the Travis docs you can add the following to your .travis.yml to remove the --depth flag:
git:
depth: false
As --depth implies --single-branch, removing this flag means that all branches will be checked out, which isn't the default behaviour.
I found that in order to get access to your whole repo you need the following:
install:
- git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
- git fetch --unshallow --tags
This way you'll have access to remote branches and tags (e.g. can do checkout).
If you're on a tag but no longer want to be in a detached HEAD state you can create a new branch that points to the tag (according to this discussion):
install:
- git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
- git fetch --unshallow --tags
- git symbolic-ref --short HEAD || git checkout -b ${TRAVIS_BRANCH}-test $TRAVIS_BRANCH
Note: git symbolic-ref --short HEAD will fail if you're in a detached HEAD state.
The problem is not really that you are in a detached branch. It is that git does not allow you to fetch the tags: git fetch --tags will only fetch the branch spcified by --branch in the git clone command you gave.
I explain this in more details this answer.
To solve you issue (checking out a specific tag) you can call a script that looks like this, after the repo is cloned:
# Keep track of where Travis put us.
# We are on a detached head, and we need to be able to go back to it.
build_head=$(git rev-parse HEAD)
# fetch the tags
git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch --tags
# checkout the tagged commit
git checkout -qf <your tag>
# now do your stuff
# go back to where we were at the beginning
git checkout ${build_head}
Run this during your build to have access to origin tags / branches
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" 1>/dev/null
git fetch origin -q
After that you can run this command to find branches containing your commit
BRANCHES=`git branch -a --contains "$TRAVIS_TAG"`
I've created a script a loooong time ago to fetch the 'environment' branch where the tag was created for continuous deployment purpose.
It may inspire you: https://gist.github.com/rolebi/a0eb1f783b7f3a5f21a631c8da1582dc
Use it like that:
TARGET_ENV="`test $TRAVIS_TAG && bash scripts/get_branch_for_git_reference.sh $TRAVIS_TAG`"
Disable git clone and then clone the repository again in the install step. The repository will be cloned only once in this way. In this "normal" clone you will able to do what ever you want.
git:
clone: false
install:
- git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG
- cd $TRAVIS_REPO_SLUG
Or you could just query the remote. Add the following to .travis.yml:
env:
global:
# get all the branches referencing this commit
- REAL_BRANCH=$(git ls-remote origin | sed -n "\|$TRAVIS_COMMIT\s\+refs/heads/|{s///p}")
# or check if we are on a particular branch:
- IS_RELEASE=$(git ls-remote origin | grep "$TRAVIS_COMMIT\s\+refs/heads/release$"
(I am surprised that the git gurus hadn’t come up with this one already)
You can convert the already existing shallow clone to a full clone. To do so execute git fetch --unshallow (available since git version 1.8.3) during the install step.
# .travis.yml
install:
- git fetch --unshallow --tags
The --tags flag forces to fetch all tags even if they don't belong to the checked out branch. This is needed if your build also depends on tags from other branches.
Has anybody has same problem?
I connected Gitlab ci with Gitlab. When test run Gitlab CI can't clone Gitlabs repo.
Got this error:
cd /home/gitlab_ci_runner/gitlab-ci-runner/tmp/builds && git clone http://gitlab-ci-token:
<mytoken>#gitlab.xlab.si/primoz_godec/scrum_app.git project-3 && cd project-3 && git checkout
<othertoken>
Cloning into 'project-3'...
fatal: protocol error: bad line length 8188
Problem was that http clone has been disabled on Gitlab. After enabling it everything was ok.
Hi this is the error that is appearing when I'm deploying using Capistrano 3 with a Rails 4 app to a Webfaction server.
The deploy has failed with an error: #<SSHKit::Command::Failed: cd
/home/username/webapps/app/repo && git rev-parse --short HEAD stdout: Nothing written
cd /home/username/webapps/app/repo && git rev-parse --short HEAD stderr: Nothing written>
My git repository is inside webfaction, I created it as --bare repository, don't know if that changes things. I set it up the URL like this in my capistrano file:
set :repo_url, '/home/username/webapps/git_app/repos/myrepo.git'
Any additional info that you may need, please ask
Thanks.
I just worked around this issue with this procedure, I don't believe it's the correct one but it helped me through:
I copied all the files (the git config files) from my repo: /home/username/webapps/git_app/repos/my_git.git/
to the mirror repo that Capistrano builds in Webfaction: /home/username/webapps/git_app/repo
Like this:
cp -a /home/username/webapps/git_app/repos/my_git.git/. /home/username/webapps/git_app/repo