├── .gitignore ├── LICENSE ├── README.md ├── index.sh └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Mathias Buus 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-clone-idempotent 2 | 3 | Like git clone, but pulls if the folder exists 4 | 5 | ``` 6 | npm install -g git-clone-idempotent 7 | ``` 8 | 9 | Useful for automated git clones/pulls 10 | 11 | ## Usage 12 | 13 | ``` sh 14 | # run it once, it will clone 15 | git-clone-idempotent git://github.com/mafintosh/git-clone-idempotent.git 16 | # run it again, it will pull 17 | git-clone-idempotent git://github.com/mafintosh/git-clone-idempotent.git 18 | ``` 19 | 20 | ## License 21 | 22 | MIT 23 | -------------------------------------------------------------------------------- /index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | REPO="$1" 4 | DEFAULT_FOLDER="$(echo "$REPO" | sed 's|.*/||' | sed 's|.git$||')" 5 | FOLDER="${2:-$DEFAULT_FOLDER}" 6 | 7 | if [ -d "$FOLDER" ]; then 8 | cd "$FOLDER" 9 | git pull 10 | else 11 | git clone "$REPO" "$FOLDER" 12 | fi 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "git-clone-idempotent", 3 | "version": "1.0.0", 4 | "description": "Like git clone, but pulls if the folder exists", 5 | "dependencies": {}, 6 | "devDependencies": {}, 7 | "bin": { 8 | "git-clone-idempotent": "./index.sh" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/mafintosh/git-clone-idempotent.git" 13 | }, 14 | "author": "Mathias Buus (@mafintosh)", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/mafintosh/git-clone-idempotent/issues" 18 | }, 19 | "homepage": "https://github.com/mafintosh/git-clone-idempotent" 20 | } 21 | --------------------------------------------------------------------------------