1

I have repo of a sdk and the team spread across. We need to keep the code private and secure from getting corrupted.

So can we have an option to enable single/specific file access to the bitbucket users via git repo setup?

Shadab K
  • 1,677
  • 1
  • 16
  • 25
  • Not file specific no. You can lock branches and only merge with an approved pull-request. – evolutionxbox May 06 '18 at 12:11
  • You CAN !!!!! using git hooks if you need specific files and for full repo, access use the bitucket configuration (repository permissions) – CodeWizard May 06 '18 at 12:25
  • Take a look here: (add the required user as well to "block" access https://stackoverflow.com/questions/35400416/what-are-some-more-forceful-ways-than-a-gitignore-to-keep-force-files-out-of/35400472#35400472 – CodeWizard May 06 '18 at 12:29

2 Answers2

1

I cant post images on comments so if this is what you are looking for I will update the answer with the full explanation on how and what to do.

You can limit and restrict access to your repo & ranches from the settings screen:

Restrict access to repository/ranches

enter image description here


Restrict changes to specific files (or allow it to certain users)

pre-receive hook

#!/bin/sh

# Check to see if this is the first commit in the repository or not
if git rev-parse --verify HEAD >/dev/null 2>&1
then
    # We compare our changes against the previous commit
    against=HEAD^
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Redirect output to screen.
exec 1>&2

# Check to see if we have updated the given file
if [ $(git diff-tree -r --name-only $against | grep <ANY FILE YOU WANT TO FILTER OUT HERE> ) ];
then

# -> ADD YOUR CODE TO CHECK CERTAIN USER 
# -> (grab it from the commit for example) 

    # Output colors
    red='\033[0;31m';
    green='\033[0;32m';
    yellow='\033[0;33m';
    default='\033[0;m';

    # personal touch :-)
    echo "${red}"
    echo "                                         "
    echo "                   |ZZzzz                "
    echo "                   |                     "
    echo "                   |                     "
    echo "      |ZZzzz      /^\            |ZZzzz  "
    echo "      |          |~~~|           |       "
    echo "      |        |-     -|        / \      "
    echo "     /^\       |[]+    |       |^^^|     "
    echo "  |^^^^^^^|    |    +[]|       |   |     "
    echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
    echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
    echo "  |       |  []   /^\   []   |+[]+   |   "
    echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
    echo "  |[]+    |      || ||       |[]+    |   "
    echo "  |_______|------------------|_______|   "
    echo "                                         "
    echo "                                         "
    echo "${red} You are not allowed to commit this file    "
    echo "                                         "
    echo "${default}"
fi;

# set the exit code to 0 or 1 based upon your needs
# 0 = good to push
# 1 = exit without pushing.
exit 0;

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
1

No, it's not.

For bitbucket git repo, there is no way to specify access permission for files for now.

There are three kinds of premissions you can set on bitbucket repo: Admin, Write and Read. Even for the users who have only read permission, they can access to all the files of the repo.

More details, you can refer the document Using repository permissions, and the post Can i set files & folders permissions in Bitbucket.

BTW: if you want to suggest the feature (enable to set permission for files/folders) to bitbucket, you can feedback by creating a new issue here.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74