post-clone

A method for replicating or mimicking a post-commit git hook.

https://github.com/gittoolbox/post-clone

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.1%) to scientific vocabulary

Keywords

git-hooks post-clone wolfsoftware
Last synced: 6 months ago · JSON representation ·

Repository

A method for replicating or mimicking a post-commit git hook.

Basic Info
  • Host: GitHub
  • Owner: GitToolbox
  • License: mit
  • Language: Shell
  • Default Branch: master
  • Homepage:
  • Size: 165 KB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 3
  • Releases: 1
Topics
git-hooks post-clone wolfsoftware
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Contributing Funding License Code of conduct Citation Codeowners Security

README.md

GitToolbox logo
Github Build Status License Created
Release Released Commits since release

WARNING

Implementing this is highly dangerous unless you fully control the repository and its contents. Proceed with caution.

Purpose

  1. Feasibility Test: Assess the practicality of implementing a post-clone action in Git repositories.
  2. Tool Automation: Facilitate the automatic addition of tools (like git hooks) to repositories, enhancing our existing setup-hooks script.

Implementation

Overload Git Command

Modify your shell profile to replace the native git command with a custom wrapper. This can be achieved by adding the following to your .bashprofile, .bashrc or .bashaliases.

shell function git() { command git-wrapper "$@" }

Git Wrapper Script

Create a git-wrapper script that manages the cloning process and triggers a post-clone action. This scripts needs to be able to run from anywhere, we recommend placing it in your ~/bin directory or any other directory that is part of your $PATH.

```shell

!/usr/bin/env bash

function getgitroot() { local repo

IFS=' ' read -r -a array <<< "$@"

repo=${array[-1]}
repo=${repo##*/}
repo=${repo%%.*}
realpath "${repo}"

}

function main() { if [[ $1 == "clone" ]]; then shift

    if command git clone "$@"; then
        root=$(get_git_root "$@")
        if [[ -d "${root}" ]]; then
            command post-clone "$root"
        fi
    fi
 else
    command git "$@";
 fi

}

main "$@" ```

Post-clone Script

Create a post-clone script which is executed by the git wrapper. This script also needs to be able to run from anywhere, we recommend placing it in your ~/bin directory or any other directory that is part of your $PATH.

```shell

!/usr/bin/env bash

cd $1 echo $PWD ```

In this example we simply have the script echoing the current directory to show that it is indeed executing inside the newly cloned repository.

Real World Example

Expand the post-clone script to execute additional scripts.

```shell

!/usr/bin/env bash

cd $1 bash repo-post-clone.sh ```

This is a very overly-simplified example!

Security Measures

To prevent unauthorized modifications:

  1. Repository Whitelist: Ensure the repository is in a list of approved repositories.
  2. Ownership Verification: Extend checks to verify the repository's owning organization.

Example with Security Checks

```shell

!/usr/bin/env bash

safe_repos=("GitToolbox/post-clone")

Function to check if a value is in an array

function not_in() { local array="$1[@]" local seeking="$2" local in=0

for element in "${!array}"; do if [[ "$element" == "$seeking" ]]; then in=1 break fi done return $in }

cd $1

Get the remote URL of the repository

remote_url=$(git config --get remote.origin.url)

Check if remote_url is empty

if [ -z "$remote_url" ]; then echo "This directory is not a Git repository or has no remote origin set. Aborting!" exit 1 fi

Extract the org and repo name from the URL

Support different URL formats (HTTPS and SSH)

if [[ $remoteurl =~ ^https:// ]]; then # HTTPS URL format: https://github.com/org/repo.git orgname=$(echo "$remoteurl" | awk -F'/' '{print $(NF-1)}') reponame=$(echo "$remoteurl" | awk -F'/' '{print $NF}' | sed 's/.git$//') elif [[ $remoteurl =~ ^git@ ]]; then # SSH URL format: git@github.com:org/repo.git orgname=$(echo "$remoteurl" | awk -F'[/:]' '{print $(NF-1)}') reponame=$(echo "$remoteurl" | awk -F'[/:]' '{print $NF}' | sed 's/.git$//') else echo "Unsupported URL format. Aborting!" exit 1 fi

if notin saferepos "$orgname/$reponame"; then echo "This is not from an a safe source - Aborting!" exit 1 fi

echo "Executing post-clone.sh in ${orgname}/${reponame}" bash repo-post-clone.sh ```

Conclusion

Use these scripts with caution and implement security checks to avoid potential misuse. Ensure thorough testing in a controlled environment.


Owner

  • Name: Git Toolbox
  • Login: GitToolbox
  • Kind: organization
  • Email: github@wolfsoftware.com
  • Location: United Kingdom

A collection of git snippets, tricks and useful scripts. Created by Wolf Software.

Citation (CITATION.cff)

cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: Post Clone
abstract: A method for implementing a post-commit git hook.
type: software
version: 0.1.0
date-released: 2024-05-21
repository-code: https://github.com/GitToolbox/post-clone
keywords:
  - "Wolf Software"
  - "Software"
license: MIT
authors:
  - family-names: "Wolf"
    orcid: "https://orcid.org/0009-0007-0983-2072"

GitHub Events

Total
  • Delete event: 61
  • Issue comment event: 135
  • Push event: 120
  • Pull request review event: 105
  • Pull request event: 124
  • Create event: 63
Last Year
  • Delete event: 61
  • Issue comment event: 135
  • Push event: 120
  • Pull request review event: 105
  • Pull request event: 124
  • Create event: 63

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 44
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.5
  • Merged pull requests: 33
  • Bot issues: 0
  • Bot pull requests: 44
Past Year
  • Issues: 0
  • Pull requests: 44
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.5
  • Merged pull requests: 33
  • Bot issues: 0
  • Bot pull requests: 44
Top Authors
Issue Authors
  • dependabot[bot] (2)
Pull Request Authors
  • dependabot[bot] (83)
Top Labels
Issue Labels
dependabot: dependencies (2) dependabot: ecosystem : github actions (2) dependabot: auto approve (2) dependabot: auto merge (2)
Pull Request Labels
dependabot: dependencies (83) dependabot: ecosystem : github actions (83) dependabot: auto approve (72) dependabot: auto merge (72) dependabot: manual merge (2)

Dependencies

.github/workflows/cicd.yml actions
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
.github/workflows/citation-validation.yml actions
  • ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • citation-file-format/cffconvert-github-action 4cf11baa70a673bfdf9dad0acc7ee33b3f4b6084 composite
  • ruby/setup-ruby 943103cae7d3f1bb1e4951d5fcc7928b40e4b742 composite
.github/workflows/delete-old-workflow-runs.yml actions
  • Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
  • Mattraks/delete-workflow-runs 39f0bbed25d76b34de5594dceab824811479e5de composite
.github/workflows/dependabot.yml actions
  • dependabot/fetch-metadata 5e5f99653a5b510e8555840e80cbf1514ad4af38 composite
.github/workflows/document-validation.yml actions
  • ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • actions/setup-node 60edb5dd545a775178f52524783378180af0d1f8 composite
  • ruby/setup-ruby 943103cae7d3f1bb1e4951d5fcc7928b40e4b742 composite
.github/workflows/generate-release.yml actions
  • Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
.github/workflows/generate-test-release.yml actions
  • Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
.github/workflows/greetings.yml actions
  • actions/first-interaction 34f15e814fe48ac9312ccf29db4e74fa767cbab7 composite
.github/workflows/purge-deprecated-workflow-runs.yml actions
  • Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
  • otto-de/purge-deprecated-workflow-runs 31a4e821d43e9a354cbd65845922c76e4b4b3633 composite
.github/workflows/repository-validation.yml actions
  • ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • actions/setup-go cdcb36043654635271a94b9a6d1392de5bb323a7 composite
  • actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
.github/workflows/security-hardening.yml actions
  • actions/checkout a5ac7e51b41094c92402da3b24376905380afc29 composite
  • zgosalvez/github-actions-ensure-sha-pinned-actions 40e45e738b3cad2729f599d8afc6ed02184e1dbd composite
.github/workflows/stale.yml actions
  • Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
  • actions/stale 28ca1036281a5e5922ead5184a1bbf96e5fc984e composite