├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md ├── LICENSE ├── sparse-checkout ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. In these conditions ... 16 | 2. I executed this command ... 17 | 4. See this error ... 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Desktop (please complete the following information):** 26 | - Bash: [e.g. v4.4.19] 27 | - OS [e.g. MacOSX Catalina] 28 | - Version of Sparse-Checkout [e.g. v1.0.0] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lemi Orhan Ergin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sparse-checkout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | # FUNCTIONS 6 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | 8 | function apply() { 9 | local folder_names 10 | folder_names=$1 11 | 12 | IFS=', ' read -r -a folder_names_arr <<<"${folder_names}" 13 | 14 | for folder_name in "${folder_names_arr[@]}"; do 15 | if [ ! -d "$folder_name" ]; then 16 | echo " :> [ERROR] Invalid parameter ($folder_name). Use a valid folder name instead." 17 | exit 2 18 | fi 19 | done 20 | 21 | pwd=$(pwd) 22 | 23 | if [ ! -f "${pwd}/.sparse-checkout" ]; then 24 | echo " :> [ERROR] .sparse-checkout file does not exist in project's root folder." 25 | exit 3 26 | fi 27 | 28 | IFS=$'\n' read -d '' -r -a keep_folders_arr < "${pwd}/.sparse-checkout" 29 | 30 | 31 | echo " :> Sparse checkout will be applied for ${folder_names}" 32 | 33 | git config core.sparsecheckout true 34 | 35 | echo "/*" >.git/info/sparse-checkout 36 | 37 | pipe_delimited_keep_folders=$( 38 | IFS=$'|' 39 | echo "${keep_folders_arr[*]}" 40 | ) 41 | pipe_delimited_folder_names=$( 42 | IFS=$'|' 43 | echo "${folder_names_arr[*]}" 44 | ) 45 | 46 | INCLUDED_FOLDERS=".*(${pipe_delimited_keep_folders}|${pipe_delimited_folder_names}).*" 47 | for d in */; do 48 | if [[ ! "$d" =~ $INCLUDED_FOLDERS ]]; then 49 | echo "!${d}" >>.git/info/sparse-checkout 50 | fi 51 | done 52 | 53 | git read-tree -mu HEAD 54 | 55 | echo " :> Removing irrelevant folders" 56 | git clean -fd &>/dev/null 57 | 58 | for d in */; do 59 | if [[ ! "$d" =~ $INCLUDED_FOLDERS ]]; then 60 | rm -rf "${d}" 61 | fi 62 | done 63 | 64 | echo " :> Sparse checkout completed for ${folder_names}" 65 | } 66 | 67 | function reset() { 68 | echo "/*" >.git/info/sparse-checkout 69 | git read-tree -mu HEAD 70 | git config core.sparseCheckout false 71 | git reset --hard HEAD 72 | echo " :> Sparse checkout is resetted. All folders are accessible for now." 73 | } 74 | 75 | function check_clean_state() { 76 | output=$(git status --porcelain) 77 | if [[ -n ${output} ]]; then 78 | echo " :> [ERROR] Uncommitted changes exist. Terminating." 79 | exit 4 80 | fi 81 | } 82 | 83 | function usage() { 84 | echo "Usage:" 85 | echo "sparse-checkout help" 86 | echo "sparse-checkout reset" 87 | echo "sparse-checkout apply FOLDER_NAME_1 FOLDER_NAME_2 FOLDER_NAME_3 [FOLDER_NAME_N]" 88 | } 89 | 90 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 91 | # MAIN 92 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93 | 94 | OPERATION=$1 95 | FOLDER_NAMES=${*:2} 96 | 97 | check_clean_state 98 | if [ "$OPERATION" == "apply" ]; then 99 | echo " :> Sparse-checkout will be resetted before enabling" 100 | reset 101 | apply "$FOLDER_NAMES" 102 | elif [ "$OPERATION" == "reset" ]; then 103 | reset 104 | elif [ "$OPERATION" == "help" ]; then 105 | usage 106 | else 107 | echo "Invalid parameter ($OPERATION)." 108 | usage 109 | fi 110 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** 4 | 5 | - [Contributing](#contributing) 6 | - [We Develop with Github](#we-develop-with-github) 7 | - [We Use Github Flow, So All Code Changes Happen Through Pull Requests](#we-use-github-flow-so-all-code-changes-happen-through-pull-requests) 8 | - [Any contributions you make will be under the MIT Software License](#any-contributions-you-make-will-be-under-the-mit-software-license) 9 | - [Report bugs using Github's issues](#report-bugs-using-githubs-issues) 10 | - [Write bug reports with detail, background, and sample code](#write-bug-reports-with-detail-background-and-sample-code) 11 | - [License](#license) 12 | - [References](#references) 13 | 14 | 15 | 16 | # Contributing 17 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 18 | 19 | - Reporting a bug 20 | - Discussing the current state of the code 21 | - Submitting a fix 22 | - Proposing new features 23 | - Becoming a maintainer 24 | 25 | ## We Develop with Github 26 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 27 | 28 | ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests 29 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests: 30 | 31 | 1. Fork the repo and create your branch from `master`. 32 | 2. If you've added code that should be tested, add tests. 33 | 3. If you've changed APIs, update the documentation. 34 | 4. Ensure the test suite passes. 35 | 5. Make sure your code lints. 36 | 6. Issue that pull request! 37 | 38 | ## Any contributions you make will be under the MIT Software License 39 | In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern. 40 | 41 | ## Report bugs using Github's [issues](https://github.com/umutphp/php-docker-images-for-ci/issues) 42 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy! 43 | 44 | ## Write bug reports with detail, background, and sample code 45 | [This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report which is not a bad model. 46 | 47 | **Great Bug Reports** tend to have: 48 | 49 | - A quick summary and/or background 50 | - Steps to reproduce 51 | - Be specific! 52 | - Give sample code if you can. 53 | - What you expected would happen 54 | - What actually happens 55 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 56 | 57 | ## License 58 | By contributing, you agree that your contributions will be licensed under its MIT License. 59 | 60 | ## References 61 | This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) 62 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct.html](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html) 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq) 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EASY SPARSE CHECKOUT 2 | 3 | - [Installation](#installation) 4 | * [via Homebrew](#via-homebrew) 5 | * [via Git Clone](#via-git-clone) 6 | - [CLI Options](#cli-options) 7 | * [Applying](#applying) 8 | * [Resetting](#resetting) 9 | - [How It Works](#how-it-works) 10 | - [Contribute](#contribute) 11 | - [Code of Conduct](#code-of-conduct) 12 | - [License](#license) 13 | 14 | If you are working with mono repos and if you are not at the beginning of your product, you may need to deal with huge number of files in your IDE. Opening that number of files might cause high memory usage, long indexing time and a lot of wait times while working at your IDE. 15 | 16 | [Sparse checkout](https://git-scm.com/docs/git-read-tree) simply help you work on the folders you really need to work on and dismiss all the others. It simply makes huge mono repos managable by your IDE. 17 | 18 | ## Installation 19 | 20 | ### via Homebrew 21 | If you are working at Mac and Homebrew installed, you can use the following commands to install. 22 | ``` 23 | brew tap lemiorhan/sparse-checkout 24 | brew install sparse-checkout 25 | ``` 26 | Do not forget to create `.sparse-checkout` file in your project's root folder and add relative paths of the folders you want to keep one per line. 27 | 28 | 29 | ### via Git Clone 30 | 1. Clone the project to a folder you desire. 31 | 2. Be sure that you have execution rights of the script. If you cannot execute it, assign permission by `chmod sparse-checkout 750` command. 32 | 3. Open/create `.sparse-checkout` file in your project's root folder and add each folder to keep by default line by line. 33 | 4. Copy the script to `/usr/local/bin` folder in order to access directly 34 | 35 | ## CLI Options 36 | 37 | After succesfull installation, you can display the options as follows. 38 | 39 | ### Applying 40 | 41 | ``` 42 | sparse-checkout apply FOLDER_NAME_1 FOLDER_NAME_2 FOLDER_NAME_3 [FOLDER_NAME_N] 43 | ``` 44 | You can add any number of folder names you need to keep. Please note that the list of folder names at `.sparse-checkout` folder are the ones which will be kept by default. By giving a folder name as the parameter, you will be able to keep dynamically, as you wish. 45 | 46 | Please also note that the files in the root folder are kept too. When you apply sparse checkout, you won't lose unkept folders. They are still kept by git inside .git folder as compressed objects. You only don't see them at working copy as source code. `git status` does not mention any deletion, don't worry. You will still have access to all commits. You can still use all git commands safely. 47 | 48 | ### Resetting 49 | ``` 50 | sparse-checkout reset 51 | ``` 52 | Simply resets sparse checkout and makes all folders accessible again. 53 | 54 | ## How It Works 55 | 56 | Sparse checkout requires a few steps to be applied. 57 | ``` 58 | git config core.sparsecheckout true 59 | echo "/*" >.git/info/sparse-checkout 60 | echo "!FOLDER_TO_REMOVE" >>.git/info/sparse-checkout 61 | git read-tree -mu HEAD 62 | ``` 63 | Folders to keep and remove should be put into `.git/info/sparse-checkout` file. Therefore we add `/*` as the first line to keep files in the root folder and add each folder to be removed one by one by putting exclamation mark to the begining of each line. `git read-tree` makes the magic. 64 | 65 | The script resets sparse-checkout before applies it. Normally when you call the script to keep FOLDER_A when sparse checkout has already been applied before for FOLDER_B, the script fails. Resetting before applying makes it safer. 66 | 67 | ## Contribute 68 | 69 | Any contributions will be welcomed! Please check our [contributing](CONTRIBUTING.md) page about details 70 | 71 | ## Code of Conduct 72 | 73 | Please check our [code of conduct](CODE_OF_CONDUCT.md) page for efficient collaboration and communication. 74 | 75 | ## License 76 | 77 | This project licensed under [MIT](LICENSE). 78 | --------------------------------------------------------------------------------