Skip to content

Instantly share code, notes, and snippets.

@realityforge
Last active February 5, 2019 23:48
Show Gist options
  • Select an option

  • Save realityforge/554fbe5cc516e7da52abe0850c33861f to your computer and use it in GitHub Desktop.

Select an option

Save realityforge/554fbe5cc516e7da52abe0850c33861f to your computer and use it in GitHub Desktop.

Revisions

  1. realityforge renamed this gist Feb 5, 2019. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions setup_repo.rb → externalize.rb
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,18 @@
    PROJECT_NAME='graphql-java'
    PROJECT_SLUG='graphql-java'
    UPSTREAM_OWNER='graphql-java'
    PROJECT_NAME='jsinterop-generator'
    PROJECT_SLUG='jsinterop-generator'
    UPSTREAM_OWNER='google'
    LOCAL_OWNER='realityforge'
    LOCAL_BRANCHES_TO_KEEP=%w()
    LOCAL_BRANCHES_TO_KEEP=%w(TravisCiIntegration)

    #WARNING this will delete local branches which may contain your changes
    DELETE_LOCAL_BRANCHES=true



    def mysystem(command, fail_on_error = true)
    puts "system (#{Dir.pwd}): #{command}" if @verbose
    system(command) || !fail_on_error || (raise "Error executing #{command} in #{Dir.pwd}")
    end

    mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git`") unless File.exist?(PROJECT_SLUG)
    mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git") unless File.exist?(PROJECT_SLUG)

    Dir.chdir PROJECT_SLUG

  2. realityforge revised this gist Aug 28, 2017. 1 changed file with 20 additions and 12 deletions.
    32 changes: 20 additions & 12 deletions setup_repo.rb
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,42 @@
    PROJECT_NAME='Schmooze'
    PROJECT_SLUG='schmooze'
    UPSTREAM_OWNER='Shopify'
    PROJECT_NAME='graphql-java'
    PROJECT_SLUG='graphql-java'
    UPSTREAM_OWNER='graphql-java'
    LOCAL_OWNER='realityforge'
    LOCAL_BRANCHES_TO_KEEP=%w()

    #WARNING this will delete local branches which may contain your changes
    DELETE_LOCAL_BRANCHES=true



    def mysystem(command, fail_on_error = true)
    puts "system (#{Dir.pwd}): #{command}" if @verbose
    system(command) || !fail_on_error || (raise "Error executing #{command} in #{Dir.pwd}")
    end

    mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git`")
    mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git`") unless File.exist?(PROJECT_SLUG)

    Dir.chdir PROJECT_SLUG

    mysystem("git remote add upstream https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git")
    mysystem("git remote add upstream https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git", false)

    mysystem("git fetch upstream")
    mysystem("git checkout upstream/master")
    mysystem("git branch upstream")
    mysystem("git branch -f upstream")
    mysystem("git checkout upstream")
    mysystem("git push origin upstream")
    mysystem("git push --set-upstream -f origin upstream")

    if DELETE_LOCAL_BRANCHES
    `git ls-remote --heads --refs 2>/dev/null`.split("\n").each do |line|
    if line =~ /^.*refs\/heads\/(.*)$/
    head = $1
    next if %w(master upstream).include?(head)
    next if (LOCAL_BRANCHES_TO_KEEP + %w(master upstream)).include?(head)
    puts "Removing branch #{head}"
    mysystem("git push origin :#{head}")
    mysystem("git branch -d #{head}")
    mysystem("git branch -d #{head}", false)
    end
    end
    end

    `git ls-remote --tags --refs 2>/dev/null`.split("\n").each do |line|
    if line =~ /^.*refs\/tags\/(.*)$/
    @@ -39,7 +47,7 @@ def mysystem(command, fail_on_error = true)
    end
    end

    mysystem("git branch -d master")
    mysystem("git branch -d master", false)
    mysystem("git checkout --orphan master")
    mysystem("git rm --cached -r .")
    mysystem("git add .")
    @@ -48,11 +56,11 @@ def mysystem(command, fail_on_error = true)
    IO.write("README.md",<<CONTENT)
    # Peter Donald's #{PROJECT_NAME} Repository
    This repository contains feature branches for the upstream repository: [#{PROJECT_NAME}](https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git).
    This repository contains feature branches for the upstream repository: [#{PROJECT_NAME}](https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}).
    It doesn not contain a meaningful master branch.
    CONTENT

    mysystem("git add -f README.md")
    mysystem('git commit -m "Add a README that describes the purpose of the repository."')
    mysystem("git push --set-upstream -f origin master")

    mysystem("git checkout upstream")
  3. realityforge revised this gist Aug 28, 2017. 2 changed files with 58 additions and 19 deletions.
    58 changes: 58 additions & 0 deletions setup_repo.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    PROJECT_NAME='Schmooze'
    PROJECT_SLUG='schmooze'
    UPSTREAM_OWNER='Shopify'
    LOCAL_OWNER='realityforge'

    def mysystem(command, fail_on_error = true)
    puts "system (#{Dir.pwd}): #{command}" if @verbose
    system(command) || !fail_on_error || (raise "Error executing #{command} in #{Dir.pwd}")
    end

    mysystem("git clone https://github.com/#{LOCAL_OWNER}/#{PROJECT_SLUG}.git`")

    Dir.chdir PROJECT_SLUG

    mysystem("git remote add upstream https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git")

    mysystem("git fetch upstream")
    mysystem("git checkout upstream/master")
    mysystem("git branch upstream")
    mysystem("git checkout upstream")
    mysystem("git push origin upstream")

    `git ls-remote --heads --refs 2>/dev/null`.split("\n").each do |line|
    if line =~ /^.*refs\/heads\/(.*)$/
    head = $1
    next if %w(master upstream).include?(head)
    puts "Removing branch #{head}"
    mysystem("git push origin :#{head}")
    mysystem("git branch -d #{head}")
    end
    end

    `git ls-remote --tags --refs 2>/dev/null`.split("\n").each do |line|
    if line =~ /^.*refs\/tags\/(.*)$/
    tag = $1
    puts "Removing tag #{tag}"
    mysystem("git push origin :#{tag}")
    mysystem("git tag -d #{tag}")
    end
    end

    mysystem("git branch -d master")
    mysystem("git checkout --orphan master")
    mysystem("git rm --cached -r .")
    mysystem("git add .")
    mysystem("git reset --hard")

    IO.write("README.md",<<CONTENT)
    # Peter Donald's #{PROJECT_NAME} Repository
    This repository contains feature branches for the upstream repository: [#{PROJECT_NAME}](https://github.com/#{UPSTREAM_OWNER}/#{PROJECT_SLUG}.git).
    It doesn not contain a meaningful master branch.
    CONTENT

    mysystem("git add -f README.md")
    mysystem('git commit -m "Add a README that describes the purpose of the repository."')
    mysystem("git push --set-upstream -f origin master")

    19 changes: 0 additions & 19 deletions setup_repo.sh
    Original file line number Diff line number Diff line change
    @@ -1,19 +0,0 @@
    git clone https://github.com/realityforge/RxJS.git
    cd RxJS
    git remote add upstream https://github.com/Reactive-Extensions/RxJS.git
    git fetch upstream
    git checkout upstream/master
    git branch upstream
    git checkout upstream
    git push origin upstream
    git branch -d master
    git checkout --orphan master
    git rm --cached -r .
    echo "# Peter Donald's RxJS Repository
    This repository simply is used to submit commits back to the upstream [RxJS](https://github.com/Reactive-Extensions/RxJS.git)
    repository and thus only contains feature branches and no meaningful master branch.
    " > README.md
    git add -f README.md
    git commit -m "Add a README that describes the purpose of the repository."
    git push --set-upstream -f origin master
  4. realityforge renamed this gist Aug 28, 2017. 1 changed file with 0 additions and 0 deletions.
  5. realityforge created this gist Aug 28, 2017.
    19 changes: 19 additions & 0 deletions Setup Git Repository For External Contributions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    git clone https://github.com/realityforge/RxJS.git
    cd RxJS
    git remote add upstream https://github.com/Reactive-Extensions/RxJS.git
    git fetch upstream
    git checkout upstream/master
    git branch upstream
    git checkout upstream
    git push origin upstream
    git branch -d master
    git checkout --orphan master
    git rm --cached -r .
    echo "# Peter Donald's RxJS Repository

    This repository simply is used to submit commits back to the upstream [RxJS](https://github.com/Reactive-Extensions/RxJS.git)
    repository and thus only contains feature branches and no meaningful master branch.
    " > README.md
    git add -f README.md
    git commit -m "Add a README that describes the purpose of the repository."
    git push --set-upstream -f origin master