salewski / ads-github-tools

Manage a large number of GitHub repos (command line tools)
https://salewski.github.io/ads-github-tools/
Other
5 stars 0 forks source link

add tool(s) to convert local repos between triangular and non-triangular setups #40

Open salewski opened 5 years ago

salewski commented 5 years ago

This issue is related to issue #38 and issue #39.

With changes in the default behavior of the git-hub tool when cloning repositories at that tool's 1.0.0 release (see issue #39 for more info), I have collections of repos beneath a common parent directory that have inconsistent setups: those that were cloned using pre-1.0.0 verions of git-hub have an 'origin' remote that points to the user's GitHub fork and have a non-triangular setup. Those that were cloned using 1.0.0 or later versions of git-hub have a 'fork' remote that points to the user's GitHub fork and have a triangular setup.

While both setups have their adherents, having a collection of repos setup inconsistently is confusing. We should provide tooling to report on such inconsistencies on locally cloned repos beneath a given directory, and also provide ways to migrate them all from one setup to the other.

For example, here's a one-liner to detect all repos that have been setup with a 'fork' remote:

    $ find -L . -mindepth 1 -maxdepth 1 -type d | sort | while read -r rpath; do test -d "${rpath}/.git" || continue; echo && echo $rpath && ( cd "$rpath" && git remote -v ) || break; done | perl -00 -wne '$_ =~ /fork/ && print'
    ...
    ./tlsh
    fork    git@github.com:salewski/tlsh.git (fetch)
    fork    git@github.com:salewski/tlsh.git (push)
    upstream        git@github.com:trendmicro/tlsh.git (fetch)
    upstream        git@github.com:trendmicro/tlsh.git (push)

    ./ttycat
    fork    git@github.com:salewski/ttycat.git (fetch)
    fork    git@github.com:salewski/ttycat.git (push)
    upstream        git@github.com:t3nsor/ttycat.git (fetch)
    upstream        git@github.com:t3nsor/ttycat.git (push)
    ...
salewski commented 4 years ago

For renaming a "fork" remote to "origin" (and related), there is a prototype script in the contrib/ directory:

    contrib/gh-remote-fixname-fork-to-origin

Example usage:

Example 1: Simple use from within a repo working directory

    $ gh-remote-fixname-fork-to-origin
    gh-remote-fixname-fork-to-origin (info): no remote named 'origin' found (okay)
    gh-remote-fixname-fork-to-origin (info): renaming remote 'fork' => 'origin'
    gh-remote-fixname-fork-to-origin (info): changing git-config key 'hub.forkremote' value from 'fork' to 'origin'

Example 2: Fix-up several repo working dirs from a parent dir

    $ for rname in my-repo1 my-repo2 my-repo3; do ( unset CDPATH; cd "$rname" && echo && echo working on: $rname && gh-remote-fixname-fork-to-origin ) || break; done

    working on: my-repo1
    gh-remote-fixname-fork-to-origin (info): no remote named 'origin' found (okay)
    gh-remote-fixname-fork-to-origin (info): renaming remote 'fork' => 'origin'
    gh-remote-fixname-fork-to-origin (info): changing git-config key 'hub.forkremote' value from 'fork' to 'origin'

    working on: my-repo3
    gh-remote-fixname-fork-to-origin (info): no remote named 'origin' found (okay)
    gh-remote-fixname-fork-to-origin (info): renaming remote 'fork' => 'origin'
    gh-remote-fixname-fork-to-origin (info): changing git-config key 'hub.forkremote' value from 'fork' to 'origin'

    working on: my-repo3
    gh-remote-fixname-fork-to-origin (info): no remote named 'origin' found (okay)
    gh-remote-fixname-fork-to-origin (info): renaming remote 'fork' => 'origin'
    gh-remote-fixname-fork-to-origin (info): changing git-config key 'hub.forkremote' value from 'fork' to 'origin'