1

My system is centos 7.4 with git 1.8.3.
Based on this post,I set sparse-checkout in my remoteserver bare repo as below:

!README.md
!.scrutinizer.yml
!.idea/*
!.idea_modules/*
/*

And I think permission is right:

[root@localhost info]# ls -al
total 8
drwxr-xr-x 2 root root  44 Jan 28 11:17 .
drwxr-xr-x 7 root root 132 Jan 28 11:33 ..
-rw-r--r-- 1 root root 240 Jan 28 14:33 exclude
-rw-r--r-- 1 root root  58 Jan 28 11:17 sparse-checkout

When I git push remoteserver master ,post-receive hook will run:
git --work-tree="$DEPLOY_DIR" --git-dir="$GIT_DIR" checkout -f

The problem is :
README.md and .scrutinizer.yml still checkout.

How to make README.md and .scrutinizer.yml not checkout as setting in sparse-checkout?

Community
  • 1
  • 1
kittygirl
  • 2,255
  • 5
  • 24
  • 52

1 Answers1

1

Try first:

git --work-tree="$DEPLOY_DIR"  --git-dir="$GIT_DIR" config core.sparsecheckout true

Then your hook can go ahead and checkout the content, which should respect the sparsecheckout directive, with the exclusions you have declared.

But: Git 1.8.3 is rather ancient: make sure and upgrade it first if possible.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried 3 ways:1.recreate repo...2.run your script under remote repo...3.put your script in post-receive hook.no success. – kittygirl Jan 29 '19 at 07:29
  • @kittygirl in the remote repo folder, do you see a file name `config`? In that file, do you see a `core.sparsecheckout` line? – VonC Jan 29 '19 at 07:48
  • yes.`config` content are:`[core] repositoryformatversion = 0 filemode = false bare = true autocrlf = false safecrlf = true sparsecheckout = true ` – kittygirl Jan 29 '19 at 08:22
  • @kittygirl Can you try in your hook a `git --work-tree="$DEPLOY_DIR" --git-dir="$GIT_DIR" checkout -f --` (with a final ` --`) to force checkout of the files? – VonC Jan 29 '19 at 08:27
  • @kittygirl Also, can you test and delete `README.md` and `.scrutinizer.yml`, then try again to push and see if your hook does re-create those files, or keep them deleted from the working tree? – VonC Jan 29 '19 at 08:28
  • tried your last 2 comments,even I `rm -f README.md .scrutinizer.yml`,hook re-create those 2 files.Maybe that's a bug? – kittygirl Jan 29 '19 at 08:35
  • @kittygirl For testing, can you try and put `/*` in the first line, as I did back in 2014 in https://stackoverflow.com/a/25699265/6309? – VonC Jan 29 '19 at 08:52
  • @kittygirl Also for testing (as a separate test), can you replace `$GIT_DIR` by the full path to your bare repo on that remote server? Just to make sure you are referencing the right path. – VonC Jan 29 '19 at 08:53
  • After latest 2 tests,still same result.Now, I add `rm -f` in `post-receive` hook,no better choice. – kittygirl Jan 29 '19 at 09:22
  • @kittygirl The only explanation I can think of is related to the version of Git used: 1.8.3. Any change of upgrading it to 2.20.1? To test if the sparse checkout does work better with a more recent version of Git. – VonC Jan 29 '19 at 09:26