Skip to content

Instantly share code, notes, and snippets.

@jupierce
Created April 7, 2020 17:24
Show Gist options
  • Select an option

  • Save jupierce/8fae5cf467e9ef41ac76a5c5d7b08137 to your computer and use it in GitHub Desktop.

Select an option

Save jupierce/8fae5cf467e9ef41ac76a5c5d7b08137 to your computer and use it in GitHub Desktop.
Merge demonstrations
#!/bin/sh
set -e
#set -o xtrace
function set_version() {
v="$1"
if [[ -z "$2" ]]; then
msg="$cb commit of $v"
else
msg="$2"
fi
echo -e "Version $v" > version
git add version
cb=$(git rev-parse --abbrev-ref HEAD)
git commit -m "$msg"
}
function side_by_side() {
msg="$1"
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift
echo "openshift branch" > openshift.branch
git log --decorate --oneline --graph >> openshift.branch
git checkout openshift-priv
echo "openshift-priv branch" > openshift-priv.branch
git log --decorate --oneline --graph >> openshift-priv.branch
git checkout $cb
clear
echo "Showing state in $D"
echo "$msg"
pr -l 1000 -m -t -W 160 openshift.branch openshift-priv.branch
read -n 1 -r -s -p $'Press enter to continue...\n'
rm -f *.branch
}
function dptp_merge_to_priv() {
id=$1
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift-priv
git merge openshift -m "Periodic merge ($id) from DPTP; pub->priv" # Emulate periodic dptp merge
check=$(git diff --check)
if [[ ! -z "$check" ]]; then
echo "Merge conflict! Unable to perform periodic merge"
git merge --abort
fi
git checkout $cb
}
function publicize() {
id=$1
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift
git merge openshift-priv -m "Publicize merge ($id); priv->pub" # Emulate /publicize
git checkout $cb
}
D=$(mktemp -d --tmpdir=${PWD} -t git-repo-XXXXX)
echo "Running in $D"
cd $D
git init .
git checkout -b 'openshift'
touch version
git add version
git commit -m 'Initial'
git checkout -b openshift-priv
git checkout openshift
set_version '4.4.0'
set_version '4.4.1'
set_version '4.4.2'
# Emulate the first DPTP merge from openshift to openshift-priv (this is a pure FF)
dptp_merge_to_priv 'A'
side_by_side "Before any CVE, public & private have the same hash"
# Add a CONFLICTING merge into openshift-priv
git checkout openshift-priv
set_version '4.4.2+FIX-B' 'Commit conflicting FIX-B to openshift-priv'
side_by_side "Right after a new embargoed merge, FIX-B is HEAD in openshift-priv"
# public is free to progress after this fix is merged into private
git checkout openshift
set_version '4.4.3'
# But the periodic merges will FAIL
dptp_merge_to_priv 'B' || true
set_version '4.4.4'
dptp_merge_to_priv 'C' || true
side_by_side "FIX-B remains embargoed but private cannot receive conflicting changes from public"
# The author must address the conflict before /publicize will work. They create and merge a PR
# to resolve the conflict as follows.
git checkout openshift-priv
git merge openshift -m 'Merging openshift to openshift-priv with conflict' || true
set_version '4.4.4+FIX-B'
side_by_side "public is merged with FIX-B and conflict resolution into openshift-priv"
# At this point openshift-priv can start receivingi non-conflicting updates from public
git checkout openshift
touch public_change
git add public_change
git commit -m 'Some public change'
dptp_merge_to_priv 'D'
# This will continue until the embargo lifts, then author issues /publicize
publicize E
side_by_side "Conflict resolution PR is gets /publicize"
# Normal merging resumes
git checkout openshift
set_version '4.4.5+FIX-B'
dptp_merge_to_priv 'F'
set_version '4.4.6+FIX-B'
dptp_merge_to_priv 'G'
side_by_side "DPTP merges continue to keep things in sync"
#!/bin/sh
# set -o xtrace
set -e
function set_version() {
v="$1"
pushd $D
echo "Version $v" > version
git add version
cb=$(git rev-parse --abbrev-ref HEAD)
git commit -m "$cb commit of $v"
popd
}
function side_by_side() {
msg="$1"
pushd $D
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift
echo "openshift branch" > openshift.branch
git log --decorate --oneline --graph >> openshift.branch
git checkout openshift-priv
echo "openshift-priv branch" > openshift-priv.branch
git log --decorate --oneline --graph >> openshift-priv.branch
git checkout $cb
clear
echo "Showing state in $D"
echo "$msg"
pr -l 1000 -m -t -W 160 openshift.branch openshift-priv.branch
read -n 1 -r -s -p $'Press enter to continue...\n'
rm -f *.branch
popd
}
function dptp_merge_to_priv() {
id=$1
pushd $D
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift-priv
git merge openshift -m "Periodic merge ($id) from DPTP; pub->priv" # Emulate periodic dptp merge
check=$(git diff --check)
if [[ ! -z "$check" ]]; then
echo "Merge conflict! Unable to perform periodic merge"
git merge --abort
fi
git checkout $cb
popd
}
function publicize() {
id=$1
pushd $D
cb=$(git rev-parse --abbrev-ref HEAD)
git checkout openshift
git merge openshift-priv -m "Publicize merge ($id); priv->pub" # Emulate /publicize
git checkout $cb
popd
}
D=$(mktemp -d --tmpdir=${PWD} -t git-repo-XXXXX)
echo "Running in $D"
pushd $D
git init .
git checkout -b 'openshift'
touch version
git add version
git commit -m 'Initial'
git checkout -b 'openshift-priv'
git checkout openshift
set_version '4.4.0'
set_version '4.4.1'
set_version '4.4.2'
# Emulate the first DPTP merge from openshift to openshift-priv (this is a pure FF)
dptp_merge_to_priv 'A'
side_by_side "Before any CVE, public & private have the same hash"
# Add a non-conflict merge into openshift-priv
git checkout openshift-priv
touch FIX-A
git add FIX-A
git commit -m 'Commit FIX-A to openshift-priv'
side_by_side "Right after a new embargoed merge, FIX-A is HEAD in openshift-priv"
# public is free to progress after this fix is merged into private
git checkout openshift
set_version '4.4.3'
# And periodic job from DPTP will continue to merge from public to private
# as long as there are no merge conflicts.
dptp_merge_to_priv 'B'
set_version '4.4.4'
dptp_merge_to_priv 'C'
side_by_side "FIX-A remains embargoed but private continues to benefit from non-conflict changes upstream"
# This will continue until the embargo lifts, then author issues /publicize
publicize C
side_by_side "FIX-A PR receives /publicize"
# Normal merging resumes
git checkout openshift
set_version '4.4.5'
dptp_merge_to_priv 'D'
set_version '4.4.6'
dptp_merge_to_priv 'E'
side_by_side "DPTP merges continue to keep things in sync"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment