mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-12 19:39:17 -05:00
First pass on fixing incorrect, multiple parents for cherry-picked commits when conflicts need to be resolved.
This commit is contained in:
@@ -35,6 +35,7 @@ type MergeState struct {
|
||||
commitSpecStr string
|
||||
preMergeWorking *RootValue
|
||||
unmergableTables []string
|
||||
IsCherryPick bool
|
||||
}
|
||||
|
||||
// todo(andy): this might make more sense in pkg merge
|
||||
@@ -193,6 +194,18 @@ func (ws WorkingSet) StartMerge(commit *Commit, commitSpecStr string) *WorkingSe
|
||||
return &ws
|
||||
}
|
||||
|
||||
// TODO: godocs!
|
||||
func (ws WorkingSet) StartCherryPick(commit *Commit, commitSpecStr string) *WorkingSet {
|
||||
ws.mergeState = &MergeState{
|
||||
commit: commit,
|
||||
commitSpecStr: commitSpecStr,
|
||||
preMergeWorking: ws.workingRoot,
|
||||
IsCherryPick: true,
|
||||
}
|
||||
|
||||
return &ws
|
||||
}
|
||||
|
||||
func (ws WorkingSet) AbortMerge() *WorkingSet {
|
||||
ws.workingRoot = ws.mergeState.PreMergeWorkingRoot()
|
||||
ws.stagedRoot = ws.workingRoot
|
||||
@@ -345,7 +358,6 @@ func (ws *WorkingSet) writeValues(ctx context.Context, db *DoltDB) (
|
||||
mergeState *datas.MergeState,
|
||||
err error,
|
||||
) {
|
||||
|
||||
if ws.stagedRoot == nil || ws.workingRoot == nil {
|
||||
return types.Ref{}, types.Ref{}, nil, fmt.Errorf("StagedRoot and workingRoot must be set. This is a bug.")
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func cherryPick(ctx *sql.Context, dSess *dsess.DoltSession, roots doltdb.Roots,
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
newWorkingSet := ws.StartMerge(cherryCommit, cherryStr)
|
||||
newWorkingSet := ws.StartCherryPick(cherryCommit, cherryStr)
|
||||
err = dSess.SetWorkingSet(ctx, dbName, newWorkingSet)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
|
||||
@@ -657,7 +657,7 @@ func (d *DoltSession) newPendingCommit(ctx *sql.Context, branchState *branchStat
|
||||
}
|
||||
|
||||
var mergeParentCommits []*doltdb.Commit
|
||||
if branchState.WorkingSet().MergeActive() {
|
||||
if branchState.WorkingSet().MergeActive() && branchState.WorkingSet().MergeState().IsCherryPick == false {
|
||||
mergeParentCommits = []*doltdb.Commit{branchState.WorkingSet().MergeState().Commit()}
|
||||
} else if props.Amend {
|
||||
numParentsHeadForAmend := headCommit.NumParents()
|
||||
|
||||
@@ -4348,6 +4348,11 @@ var DoltCherryPickTests = []queries.ScriptTest{
|
||||
Query: "SELECT * FROM t order by pk;",
|
||||
Expected: []sql.Row{{1, "one"}, {2, "two"}},
|
||||
},
|
||||
{
|
||||
// Assert that our new commit only has one parent (i.e. not a merge commit)
|
||||
Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');",
|
||||
Expected: []sql.Row{{1}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -4395,6 +4400,11 @@ var DoltCherryPickTests = []queries.ScriptTest{
|
||||
Query: "call dolt_cherry_pick(@commit1);",
|
||||
Expected: []sql.Row{{doltCommit, 0, 0, 0}},
|
||||
},
|
||||
{
|
||||
// Assert that our new commit only has one parent (i.e. not a merge commit)
|
||||
Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');",
|
||||
Expected: []sql.Row{{1}},
|
||||
},
|
||||
{
|
||||
Query: "SHOW TABLES;",
|
||||
Expected: []sql.Row{{"myview"}, {"table_a"}},
|
||||
@@ -4695,6 +4705,15 @@ var DoltCherryPickTests = []queries.ScriptTest{
|
||||
Query: `SELECT * FROM t;`,
|
||||
Expected: []sql.Row{{1, "ein"}},
|
||||
},
|
||||
{
|
||||
Query: "call dolt_commit('-am', 'committing cherry-pick');",
|
||||
Expected: []sql.Row{{doltCommit}},
|
||||
},
|
||||
{
|
||||
// Assert that our new commit only has one parent (i.e. not a merge commit)
|
||||
Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');",
|
||||
Expected: []sql.Row{{1}},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -38,6 +38,8 @@ table MergeState {
|
||||
from_commit_spec_str:string;
|
||||
|
||||
unmergable_tables:[string];
|
||||
|
||||
is_cherry_pick:bool;
|
||||
}
|
||||
|
||||
// KEEP THIS IN SYNC WITH fileidentifiers.go
|
||||
|
||||
@@ -165,6 +165,7 @@ type MergeState struct {
|
||||
fromCommitAddr *hash.Hash
|
||||
fromCommitSpec string
|
||||
unmergableTables []string
|
||||
IsCherryPick bool
|
||||
|
||||
nomsMergeStateRef *types.Ref
|
||||
nomsMergeState *types.Struct
|
||||
|
||||
@@ -202,6 +202,7 @@ func NewMergeState(
|
||||
commit *Commit,
|
||||
commitSpecStr string,
|
||||
unmergableTables []string,
|
||||
isCherryPick bool,
|
||||
) (*MergeState, error) {
|
||||
if vrw.Format().UsesFlatbuffers() {
|
||||
ms := &MergeState{
|
||||
@@ -209,6 +210,7 @@ func NewMergeState(
|
||||
fromCommitAddr: new(hash.Hash),
|
||||
fromCommitSpec: commitSpecStr,
|
||||
unmergableTables: unmergableTables,
|
||||
IsCherryPick: isCherryPick,
|
||||
}
|
||||
*ms.preMergeWorkingAddr = preMergeWorking.TargetHash()
|
||||
*ms.fromCommitAddr = commit.Addr()
|
||||
@@ -223,6 +225,7 @@ func NewMergeState(
|
||||
return nil, err
|
||||
}
|
||||
return &MergeState{
|
||||
IsCherryPick: isCherryPick,
|
||||
nomsMergeStateRef: &ref,
|
||||
nomsMergeState: &v,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user