Skip to content

Commit c3f3848

Browse files
authored
Merge pull request #38 from VariantSync/benjamin/replication
Create a script for archiving source repositories
2 parents 79f9619 + d6aafdf commit c3f3848

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

docs/replication/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Replication
2+
3+
The script `create-forks-on-github.sh` can be used to create forks of all the
4+
repositories in the `../../../DiffDetectiveMining/` folder. It marks them as a
5+
fork and replicates the local state in this fork. The indended use case is to
6+
provide immutable copies of all source data to make all results of this research
7+
reproducible.
8+
9+
## Usage
10+
First run:
11+
```bash
12+
./create-forks-on-github.sh
13+
```
14+
15+
It will ask some verification questions and prints all commands that it will
16+
perform. If the source repositories are not located in
17+
`../../../DiffDetectiveMining/` (relative to this file) or
18+
`../DiffDetectiveMining` (relative to the root directory of this repository) the
19+
comment character of the variable `PATH_TO_REPOSITORIES` in the second paragraph
20+
can be removed and the actual path can be set.
21+
22+
To execute the printed commands uncomment the last line of the second paragraph
23+
which disables `DRY_RUN`.
24+
25+
## Login
26+
You can either login beforehand with `gh auth login` or just run the script
27+
which will run this command for you. This script will *not* log you out once
28+
it's finished because you may want to run additional commands (or you where
29+
previously logged in).
30+
31+
## Additional notes
32+
This script should be idempotent as `gh` detects an already forked project and
33+
the performed force push should not change anything (unless the remote
34+
repository was changed).
35+
36+
## Requirements
37+
This script requires a standard UNIX environment with at least the following
38+
additional tools:
39+
- `bash`, the GNU POSIX shell
40+
- `gh`, the github command line interface
41+
- GNU `find`, the POSIX `find` with some additional options (mainly `-print0`,
42+
but this was not tested with other `find` implementations)
43+
44+
This script was tested under GNU+Linux.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
# Default settings
4+
PATH_TO_REPOSITORIES="$(dirname "${BASH_SOURCE[0]}")/../../../DiffDetectiveMining"
5+
DRY_RUN=y
6+
7+
# Override settings
8+
#PATH_TO_REPOSITORIES="absolute/path/to/directory/containing/the/respositories"
9+
# uncomment to following line, to actually run th 'gh' commands
10+
#DRY_RUN=n
11+
12+
continue-with() {
13+
echo
14+
read -p "Do you want to continue with $1? [y/N] " answer
15+
[ "$answer" == "y" ]
16+
}
17+
18+
run() {
19+
echo "\$ $*"
20+
if [ "$DRY_RUN" = "n" ]
21+
then
22+
"$@"
23+
fi
24+
}
25+
26+
repos() {
27+
find "$PATH_TO_REPOSITORIES" -mindepth 1 -maxdepth 1 -type d "$@"
28+
}
29+
30+
PATH_TO_REPOSITORIES="$(realpath "$PATH_TO_REPOSITORIES")"
31+
cd "$PATH_TO_REPOSITORIES"
32+
echo "The following repos in '$PATH_TO_REPOSITORIES' will be forked:"
33+
repos
34+
continue-with "these $(repos -print0 | tr -d -c '\0' | tr '\0' '\n' | wc -l) repos" || exit 1
35+
36+
if gh auth status |& grep -q 'You are not logged into any GitHub hosts.' &>/dev/null
37+
then
38+
run gh auth login || exit 1
39+
was_logged_in=0
40+
else
41+
echo
42+
gh auth status
43+
44+
continue-with "this account" ||
45+
{
46+
run gh auth logout &&
47+
run gh auth login || exit 1
48+
}
49+
was_logged_in=1
50+
fi
51+
52+
repos -print0 |
53+
while IFS= read -d '' -r repository
54+
do
55+
echo
56+
run cd "$repository"
57+
run gh repo fork --remote
58+
run git push -f origin
59+
done
60+
61+
if [ "$was_logged_in" = "1" ]
62+
then
63+
cat <<EOF
64+
65+
Warning: 'gh' is still logged in, to log out use
66+
67+
gh auth logout
68+
69+
EOF
70+
else
71+
echo
72+
run gh auth logout
73+
fi

0 commit comments

Comments
 (0)