diff --git a/docs/replication/README.md b/docs/replication/README.md new file mode 100644 index 000000000..db9e24668 --- /dev/null +++ b/docs/replication/README.md @@ -0,0 +1,44 @@ +# Replication + +The script `create-forks-on-github.sh` can be used to create forks of all the +repositories in the `../../../DiffDetectiveMining/` folder. It marks them as a +fork and replicates the local state in this fork. The indended use case is to +provide immutable copies of all source data to make all results of this research +reproducible. + +## Usage +First run: +```bash +./create-forks-on-github.sh +``` + +It will ask some verification questions and prints all commands that it will +perform. If the source repositories are not located in +`../../../DiffDetectiveMining/` (relative to this file) or +`../DiffDetectiveMining` (relative to the root directory of this repository) the +comment character of the variable `PATH_TO_REPOSITORIES` in the second paragraph +can be removed and the actual path can be set. + +To execute the printed commands uncomment the last line of the second paragraph +which disables `DRY_RUN`. + +## Login +You can either login beforehand with `gh auth login` or just run the script +which will run this command for you. This script will *not* log you out once +it's finished because you may want to run additional commands (or you where +previously logged in). + +## Additional notes +This script should be idempotent as `gh` detects an already forked project and +the performed force push should not change anything (unless the remote +repository was changed). + +## Requirements +This script requires a standard UNIX environment with at least the following +additional tools: +- `bash`, the GNU POSIX shell +- `gh`, the github command line interface +- GNU `find`, the POSIX `find` with some additional options (mainly `-print0`, + but this was not tested with other `find` implementations) + +This script was tested under GNU+Linux. diff --git a/docs/replication/create-forks-on-github.sh b/docs/replication/create-forks-on-github.sh new file mode 100755 index 000000000..9a40389d1 --- /dev/null +++ b/docs/replication/create-forks-on-github.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Default settings +PATH_TO_REPOSITORIES="$(dirname "${BASH_SOURCE[0]}")/../../../DiffDetectiveMining" +DRY_RUN=y + +# Override settings +#PATH_TO_REPOSITORIES="absolute/path/to/directory/containing/the/respositories" +# uncomment to following line, to actually run th 'gh' commands +#DRY_RUN=n + +continue-with() { + echo + read -p "Do you want to continue with $1? [y/N] " answer + [ "$answer" == "y" ] +} + +run() { + echo "\$ $*" + if [ "$DRY_RUN" = "n" ] + then + "$@" + fi +} + +repos() { + find "$PATH_TO_REPOSITORIES" -mindepth 1 -maxdepth 1 -type d "$@" +} + +PATH_TO_REPOSITORIES="$(realpath "$PATH_TO_REPOSITORIES")" +cd "$PATH_TO_REPOSITORIES" +echo "The following repos in '$PATH_TO_REPOSITORIES' will be forked:" +repos +continue-with "these $(repos -print0 | tr -d -c '\0' | tr '\0' '\n' | wc -l) repos" || exit 1 + +if gh auth status |& grep -q 'You are not logged into any GitHub hosts.' &>/dev/null +then + run gh auth login || exit 1 + was_logged_in=0 +else + echo + gh auth status + + continue-with "this account" || + { + run gh auth logout && + run gh auth login || exit 1 + } + was_logged_in=1 +fi + +repos -print0 | +while IFS= read -d '' -r repository +do + echo + run cd "$repository" + run gh repo fork --remote + run git push -f origin +done + +if [ "$was_logged_in" = "1" ] +then + cat <