Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testcase notes] #20: Pull request, inside one repo, between different branches #26

Open
dorawyy opened this issue Oct 21, 2017 · 2 comments

Comments

@dorawyy
Copy link
Owner

dorawyy commented Oct 21, 2017

abstract: PR2 (head branch) --- send a pull request---> PR1 (base branch) inside one repo

Scenario abstract

--> Different branches inside one repo, only Alice commits

  • PR2 branch (Pull-Request-2 branch) was derived from PR1 branch (Pull-Request-1 branch)
  • Alice and Bob worked on the same repo, Alice(PR2 branch), Bob(PR1 branch)
  • Alice made commits on PR2 branch locally
  • Alice git push origin PR2
  • Bob made no change on PR1
  • Alice made a pull request to Bob: FROM: repo1, PR2 --> TO: repo1, PR1
  • What would Bob do and meet?
    • What if he merge directly
    • What if he squash commits then merge?
    • What if he rebase then merge?

( in the scratch below, replace F1 with PR1, replace F2 with PR2)
wechatimg280

Results:

  • Option1: When create a merge commit,
    • no conflict
    • all commits on head branch (PR2 in this case) are applied directly to the base branch (PR1 in this case)
    • also a pull request merge commit is created;
    • no effect on the head branch
  • Option2: When squash commits and merge,
    • all commits on head branch (PR2 in this case) are squashed into a single commit
    • then the new commit gets applied back to the base branch (PR1 in this case).
    • the squashed new commit is a normal commit (not merge)
    • no merge commit created.
    • the two branch diverges after the pull request
    • no effect on the head branch
  • Option3: When rebase and merge,
    • rebase all ( let's say, n commits of head branch (PR2 in this case) to base branch (PR1 in this case) --> But does not change commits on the head branch (PR2 in this case)
    • all n refined (SHA changed) commits are reapplied to the base branch (PR1 in this case)
    • no merge commit created ( as rebasing first)
    • the two branch diverges after the pull request
    • no effect on the head branch ( did not get rebased, SHA still the same as previous time )

Data could be explored:

  • Option1: When create a merge commit
    • a merge commit about the pull request will be created
    • no sign for conflict
  • Option2: When create a merge commit
    • nothing left
  • Option3: When rebase and merge
    • if no conflict, would see commits on both branches with same commit info but different SHA
    • (not sure, but should be) disabled if rebasing conflicts

Detailed steps:

Step0: prep

  • create PR1 branch from master branch
  • createtest20 as test file on PR1
  • create PR2 branch from PR1 branch
# create PR1
git checkout master

git checkout -b PR1
touch test20
# edit test20

git add test20
git commit -m "testcase20: startpoint (create file test20 on PR1 branch)"
git push origin PR1

# create branch PR2
git checkout -b PR2
git push origin PR2

##### Now both PR1 and PR2 are set, at the same commit, we can start the test case

Content of test20:

screen shot 2017-10-21 at 11 55 32 am

Startpoint - project tree:

screen shot 2017-10-21 at 12 00 49 pm

Step1: Alice committed on PR2 , pushed back to remote

git checkout PR2
vim test20
# edit test20, line 20

git add test20
git commit -m "PR2: edited the file test 20, line 20"

git push origin PR2

The edit on the file test20 is:
screen shot 2017-10-21 at 12 07 51 pm

After git push origin PR2, here is the project status:
screen shot 2017-10-21 at 12 09 09 pm

Step2: Bob made no change on PR1

Nothing to do in this step
Project status after this step (same as status of step1):
screen shot 2017-10-21 at 12 09 09 pm

Step3: Alice made a pull request to merge PR1 and PR2

This is the page that Alice will see when she create a new pull request:
screen shot 2017-10-21 at 12 15 55 pm

Observation1:

  • in this pull request, there is only 1 commit, thus the default pull request title is the same as the commit message

screen shot 2017-10-21 at 12 15 55 pm

  • However, Alice modified it to something more meaningful; Alice also attached detailed information about the pull request

screen shot 2017-10-21 at 12 33 09 pm

Observation2:

  • Alice can add more commits by pushing to the PR2 branch on dorawyy/git-merge-conflicts-test.

screen shot 2017-10-21 at 12 47 46 pm

Step4: Alice work is done, now Bob's turn. He needs to decide what to do with the pull request.

Here are all the options he has:
screen shot 2017-10-21 at 12 40 51 pm

Also, here is command line instructions, telling us how to make a manual merge
screen shot 2017-10-21 at 12 43 32 pm


Option1: Create a merge commit

All commits from this branch (PR2 in this case) will be added to the base branch via a merge commit.

  • If Bob chooses to Create a merge commit, this is the page he will see, to create a `pull request merge commit:

screen shot 2017-10-21 at 12 54 13 pm

  • Here is the info input by Bob, in the merge commit:

screen shot 2017-10-21 at 12 59 51 pm

  • Then, the merge is done:

screen shot 2017-10-21 at 12 59 51 pm

Option1 Result

  • nothing changed on PR2 branch
  • all commits on PR2 branch that are merged (only 45c39f0 in this test case), are merged back to PR1 branch
  • also, the merge of the pull request explicit created a merge commit(d8cae67) (though actually fast-forward merging)

Here is commits history of PR2

screen shot 2017-10-21 at 1 01 12 pm

Here is commits history of PR1

screen shot 2017-10-21 at 1 00 59 pm

Note: the newly created commit is a merge commit, telling from the history here:
screen shot 2017-10-21 at 2 25 33 pm

Pull PR1 and PR2 to local again, merge, then push back to remote

  • sync PR1 and origin/PR1, sync PR2 and origin/PR2
git checkout PR2
git pull origin PR2

git checkout PR1
git pull origin PR1

The project status becomes:

screen shot 2017-10-21 at 1 18 45 pm

  • sync PR1 and PR2, then sync PR1 and origin/PR1, PR2 and origin/PR2
git checkout PR2
git merge PR1
git push origin PR2

screen shot 2017-10-21 at 1 29 55 pm

The project history now becomes:
screen shot 2017-10-21 at 1 30 17 pm


@dorawyy
Copy link
Owner Author

dorawyy commented Oct 21, 2017

Option2: Squash and commit

The 1( 1 in this case) commit from this branch will be added to the base branch

Current project status:
screen shot 2017-10-21 at 1 41 18 pm

Prep again

git checkout PR1
touch test20_option2
vim test20_option2

git add test20_option2
git commit -m "testcase20(option2): startpoint (create file test20_option2 on PR1 branch)"
git push origin PR1

# then sync PR2 with PR1
git checkout PR2
git merge PR1
git push origin PR2

# now the two branches are synced

Prep edit on test20_option2:
screen shot 2017-10-21 at 1 42 40 pm

After prep, the project status is:
screen shot 2017-10-21 at 1 44 34 pm

Step1: Alice made two commits on PR2 branch

  • Here is commit1:
git checkout PR2
vim test20_option2
# make changes
git add test20_option2
git commit -m "PR2: commit1, edit file test20_option2, line 16" 
  • Here is commit 2:
git checkout PR2
vim test20_option2
# make different changes
git add test20_option2
git commit -m "PR2: commit2, edit file test20_option2, line 17" 

Here is Alice's edit of commit1 and commit2:
screen shot 2017-10-21 at 1 47 31 pm

Here is the project status after commit2 is also done:
screen shot 2017-10-21 at 12 59 51 pm

  • Push all changes back to remote repo
git checkout PR2
git push origin PR2

screen shot 2017-10-21 at 1 49 45 pm

Step2:

Bob did nothing

Step3: Alice made a pull request

  • First, there is no conflict, the pull request shows there are two commits

screen shot 2017-10-21 at 1 50 56 pm

  • Second, Alice makes the pull request, here is what she filled in:

screen shot 2017-10-21 at 1 56 21 pm

screen shot 2017-10-21 at 1 56 29 pm

  • Till now, Alice's work is done. Now Bob's turn.

Step4: Bob chose to squash commits and merge

  • Bob choose to squash commits and merge

screen shot 2017-10-21 at 1 59 33 pm

  • The default window that Bob will see:

screen shot 2017-10-21 at 1 59 44 pm

  • Here are the info that Bob input:

screen shot 2017-10-21 at 2 04 42 pm

  • After squashing commits done, here is the window that Bob sees:

screen shot 2017-10-21 at 2 05 04 pm

Step5: Check history changes of branch PR1 and PR2

  • There is no change on branch PR2

screen shot 2017-10-21 at 2 09 24 pm

  • As for PR1, all commits on PR2 included in the pull request are squashed, and became 1 commit, showing up in PR1 branch's history

screen shot 2017-10-21 at 2 09 14 pm

  • Note: the squashed commit on PR1 is a normal commit, with only 1 parent.

screen shot 2017-10-21 at 2 25 24 pm

Step6: Pull all changes back to local, merge, push again ( to sync for next testcase)

git checkout PR1
git pull origin PR1
  • At this point, PR1 and PR2 diverged actually [Therefore, we need to merge them again ( though their changes actually are actually the same)
    ]

screen shot 2017-10-21 at 2 35 20 pm

  • If we try to merge via making pull request, here is what we can see:
    • we can make pull request PR1 --> PR2 or PR2 --> PR1
    • if PR1 --> PR2 , showing 1 commit
    • if PR2 --> PR1, showing 2 commits
    • See screenshot for details

screen shot 2017-10-21 at 2 39 22 pm

screen shot 2017-10-21 at 2 40 01 pm

Hint here: the merge detection happens between the the latest commit on current branch, and the latest common commit of the other branch

  • Merge PR1 and PR2 in a regular merge way: (it should be a three way merging)
# for example, merge on PR1
git checkout PR1
git merge PR2

# three-way merging, a merge commit created

Here is the merge message:
screen shot 2017-10-21 at 2 50 15 pm
The project status becomes:
screen shot 2017-10-21 at 2 51 07 pm

Then merge PR2 forward (fast-forward)

git checkout PR2
git merge PR1

The project status becomes:
screen shot 2017-10-21 at 2 52 10 pm

Then, sync to remote-tracking branches:

git checkout PR1
git push origin PR1
git checkout PR2
git push origin PR2
  • Check remote commits:

screen shot 2017-10-21 at 2 54 38 pm

screen shot 2017-10-21 at 2 54 54 pm

  • Now, the project status is:

screen shot 2017-10-21 at 2 53 41 pm

@dorawyy
Copy link
Owner Author

dorawyy commented Oct 21, 2017

Option3: Rebase and merge

The n commits from this branch will be rebased and added to the base branch

Current project status:
screen shot 2017-10-21 at 2 59 11 pm

Prep again

git checkout PR1
touch test20_option3
vim test20_option3

git add test20_option3
git commit -m "testcase20(option3): startpoint (create file test20_option3 on PR1 branch)"
git push origin PR1

# then sync PR2 with PR1
git checkout PR2
git merge PR1
git push origin PR2

# now the two branches are synced

Prep edit on test20_option3:
screen shot 2017-10-21 at 3 31 29 pm

After prep, the project status is:
screen shot 2017-10-21 at 3 32 40 pm


Step1: Alice made two commits on PR2 branch

  • Here is commit1:
git checkout PR2
vim test20_option3
# make changes
git add test20_option3
git commit -m "PR2: commit1, edit file test20_option3, line 16" 

Here is Alice's edit of commit1:
screen shot 2017-10-21 at 3 34 11 pm

  • Here is commit 2:
git checkout PR2
vim test20_option3
# make different changes
git add test20_option3
git commit -m "PR2: commit2, edit file test20_option3, line 17" 

Here is Alice's edit of commit2:
screen shot 2017-10-21 at 3 35 16 pm

  • Push all changes back to remote repo
git checkout PR2
git push origin PR2

Now the project status is:
screen shot 2017-10-21 at 3 36 16 pm


Step2:

Bob did nothing


Step3: Alice made a pull request

  • First, there is no conflict, the pull request shows there are two commits

screen shot 2017-10-21 at 3 39 05 pm

  • Second, Alice makes the pull request, here is what she filled in:

screen shot 2017-10-21 at 3 46 14 pm

screen shot 2017-10-21 at 3 46 22 pm

  • Till now, Alice's work is done. Now Bob's turn.

Step4: Bob chose to rebase and merge

  • Bob choose to rebase and merge

screen shot 2017-10-21 at 3 47 34 pm

  • The default window that Bob will see:

screen shot 2017-10-21 at 3 49 46 pm

  • Bob does not need to input anything

  • After rebasing then merge is done, here is the window that Bob sees:

screen shot 2017-10-21 at 3 51 24 pm


Step5: Check history changes of branch PR1 and PR2

  • Here is PR2

screen shot 2017-10-21 at 4 21 42 pm

  • Here is PR1

screen shot 2017-10-21 at 4 20 05 pm

  • Observations:
    • PR2 , no change
    • PR1 branch: have the 2 commits from PR2. because PR2 get rebased, then fast-forward merge back to PR1
    • the SHA of the 2 commits on PR1 is different from that of PR2 branch.

Step6: Pull all changes back to local, merge, push again ( to sync for next testcase)

  • fetch updates on PR1 and PR2 from remote
git checkout PR1
git pull origin PR1

git checkout PR2
git pull origin PR2
  • Now the two branches diverged, see the tree below:

screen shot 2017-10-21 at 4 30 13 pm

If we try to make a pull request now, both PR2 --> PR1 and PR1 --> PR2 works:

Pull request PR2 --> PR1 :

screen shot 2017-10-21 at 4 31 11 pm

Pull request PR1 --> PR2 :

screen shot 2017-10-21 at 4 30 56 pm


Step7: If making pull request PR1 --> PR2 to resolve the conflict:

Here is the pull request:
screen shot 2017-10-21 at 5 13 26 pm

Two commits included, however,

  • there is conflict if rebasing (as the screenshot above shows); thus, rebase and merge is disabled
  • create a merge commit is still abled
  • squash and commit is also abled --> but this one cannot resolve conflict, after which still diverging

-- If merging directly:
screen shot 2017-10-21 at 5 20 59 pm
-- If squashing commits and merge:
screen shot 2017-10-21 at 5 20 53 pm

Here, I choose to squash commits and merge (should have new commits on PR2):

screen shot 2017-10-21 at 5 23 12 pm

screen shot 2017-10-21 at 5 24 23 pm

If checking branch commits history now,

  • PR2:

screen shot 2017-10-21 at 5 34 32 pm

  • PR1:

screen shot 2017-10-21 at 5 34 44 pm


Step8: git pull to local and observe

screen shot 2017-10-21 at 5 36 24 pm

Now the tree diverge more, thus still needs merging


Step9: merge PR1 and PR2

git checkout PR2
git pull origin PR2
git merge PR1

(three way merging)
screen shot 2017-10-21 at 5 38 33 pm

Now the project history is like:
screen shot 2017-10-21 at 5 39 24 pm

git checkout PR1
git pull origin PR1
git merge PR2

( a fast-forward merging)
The project history becomes:
screen shot 2017-10-21 at 5 40 25 pm

# sync with remote repo
git checkout PR1
git push origin PR1

git checkout PR2
git push origin PR2

The project history becomes, all synced:

screen shot 2017-10-21 at 5 41 57 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant