Skip to content

Commit

Permalink
Fallback to conflicts when merge is done in non-tty environment (read…
Browse files Browse the repository at this point in the history
… GUI app).

Merge in GUI apps led to silent failure to merge .s7substate properly. It left .s7substate in a visually non-conflict state.
Now, if merge happens in non-tty env (we cannot interactively ask user what to do), we fallback to the conflict.
  • Loading branch information
pastey committed Oct 1, 2023
1 parent 2a79a40 commit 5ae1204
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 115 deletions.
4 changes: 3 additions & 1 deletion buildme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ fi
#
# INSTALL_PATH:
# "The directory in which to install the build products. This path is prepended by the DSTROOT."
#
# Starting with Sonoma, xcodebuild install (without clean) stopped replacing existing binary in the DSTROOT.

xcodebuild_cmd() {
# when executed as part of xcode run script phase, env is populated with settings of current project
# these headers are unwanted and may cause module import conflicts
unset USER_HEADER_SEARCH_PATHS
unset HEADER_SEARCH_PATHS
xcodebuild -target system7 -configuration Release DSTROOT="$HOME" install
xcodebuild -target system7 -configuration Release DSTROOT="$HOME" clean install
}

if ! xcodebuild_cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ echo
echo cherry-pick

# cherry-pick only last commit from 'release/documents-7.2.4'
echo M | git cherry-pick release/documents-7.2.4
S7_MERGE_DRIVER_RESPONSE="M" git cherry-pick release/documents-7.2.4
assert test 0 -eq $?

assert test plus = `cat Dependencies/ReaddleLib/RDMath.h`
17 changes: 16 additions & 1 deletion system7-tests/integration/case-mergeConflictInSubrepo-Merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,24 @@ popd > /dev/null
assert s7 rebind --stage
assert git commit -m '"up ReaddleLib"'

# first try non-interactive merge "via GUI app"
echo "emulating GUI Git client that doesn't support interactive stdin" |
git merge --no-edit experiment
assert test 0 -ne $?

echo
echo "resulting .s7substate:"
cat .s7substate
echo

assert grep '"<<<"' .s7substate > /dev/null

assert git merge --abort


echo
echo
echo m | git merge experiment
S7_MERGE_DRIVER_RESPONSE="m" git merge --no-edit experiment
assert test 0 -ne $?

echo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ assert git commit -m '"up ReaddleLib"'

echo
echo
echo L | git merge experiment
S7_MERGE_DRIVER_RESPONSE="L" git merge --no-edit experiment
assert test 0 -eq $?

echo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ assert git commit -m '"up ReaddleLib"'

echo
echo
echo R | git merge experiment
S7_MERGE_DRIVER_RESPONSE="r" git merge --no-edit experiment
assert test 0 -eq $?

echo
Expand Down
134 changes: 120 additions & 14 deletions system7-tests/mergeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,7 @@ - (void)testBothSideUpdateSubrepoToDifferentRevisionConflictResolution_Merge {

++callNumber;

if (1 == callNumber) {
// play a fool and return an option not in 'possibleOptions'
return S7ConflictResolutionOptionKeepChanged;
}
else if (2 == callNumber) {
// play a fool and return an option not in 'possibleOptions' one more time
return S7ConflictResolutionOptionDelete;
}
else if (3 == callNumber) {
// шоб да, так нет
return S7ConflictResolutionOptionKeepLocal | S7ConflictResolutionOptionKeepRemote;
}
else if (callNumber > 4) {
if (callNumber > 1) {
// it keeps asking us?
XCTFail(@"");
}
Expand All @@ -502,7 +490,7 @@ - (void)testBothSideUpdateSubrepoToDifferentRevisionConflictResolution_Merge {
saveResultToFilePath:S7ConfigFileName];
XCTAssertEqual(0, mergeExitStatus);

XCTAssertEqual(4, callNumber, @"we played a fool several times, but then responded with a valid value – `merge`");
XCTAssertEqual(1, callNumber, @"we played a fool several times, but then responded with a valid value – `merge`");

S7PrepareCommitMsgHook *prepareCommitHook = [S7PrepareCommitMsgHook new];
XCTAssertEqual(0, [prepareCommitHook runWithArguments:@[ @"merge" ]]);
Expand Down Expand Up @@ -534,6 +522,124 @@ - (void)testBothSideUpdateSubrepoToDifferentRevisionConflictResolution_Merge {
}];
}

- (void)testBothSideUpdateSubrepoToDifferentRevisionConflictResolution_KeepConflict {
__block S7Config *baseConfig = nil;
[self.env.pasteyRd2Repo run:^(GitRepository * _Nonnull repo) {
// ReaddleLib will conflict and two other will have to merge well
s7add(@"Dependencies/RDSFTP", self.env.githubRDSFTPRepo.absolutePath);
s7add(@"Dependencies/RDPDFKit", self.env.githubRDPDFKitRepo.absolutePath);
s7add(@"Dependencies/ReaddleLib", self.env.githubReaddleLibRepo.absolutePath);

[repo add:@[S7ConfigFileName, @".gitignore"]];
[repo commitWithMessage:@"add subrepos"];

baseConfig = [[S7Config alloc] initWithContentsOfFile:S7ConfigFileName];

s7push_currentBranch(repo);
}];

__block S7Config *niksConfig = nil;
__block NSString *readdleLib_niks_Revision = nil;
__block NSString *sftp_niks_Revision = nil;
[self.env.nikRd2Repo run:^(GitRepository * _Nonnull repo) {
[repo pull];

s7init_deactivateHooks();

S7PostMergeHook *postMergeHook = [S7PostMergeHook new];
const int mergeHookExitStatus = [postMergeHook runWithArguments:@[]];
XCTAssertEqual(0, mergeHookExitStatus);

GitRepository *readdleLibSubrepoGit = [GitRepository repoAtPath:@"Dependencies/ReaddleLib"];
XCTAssertNotNil(readdleLibSubrepoGit);

readdleLib_niks_Revision = commit(readdleLibSubrepoGit, @"RDGeometry.h", @"xyz", @"some useful math func");

GitRepository *sftpSubrepoGit = [GitRepository repoAtPath:@"Dependencies/RDSFTP"];
XCTAssertNotNil(sftpSubrepoGit);

sftp_niks_Revision = commit(sftpSubrepoGit, @"RDSFTP.h", @"ssh2 request", @"some usuful code");

s7rebind_with_stage();
[repo commitWithMessage:@"up ReaddleLib and RDSFTP"];

niksConfig = [[S7Config alloc] initWithContentsOfFile:S7ConfigFileName];

s7push_currentBranch(repo);
}];

[self.env.pasteyRd2Repo run:^(GitRepository * _Nonnull repo) {
GitRepository *readdleLibSubrepoGit = [GitRepository repoAtPath:@"Dependencies/ReaddleLib"];
NSString *readdleLib_pasteys_Revision =
commit(readdleLibSubrepoGit, @"RDSystemInfo.h", @"iPad 11''", @"add support for a new iPad model");

GitRepository *pdfkitSubrepoGit = [GitRepository repoAtPath:@"Dependencies/RDPDFKit"];
NSString *pdfkit_pasteys_Revision = commit(pdfkitSubrepoGit, @"RDPDFAnnotation.h", @"AP/N", @"generate AP/N");

s7rebind_with_stage();
[repo commitWithMessage:@"up ReaddleLib and RDPDFKit"];

S7Config *ourConfig = [[S7Config alloc] initWithContentsOfFile:S7ConfigFileName];

const int pushExitStatus = s7push_currentBranch(repo);
XCTAssertNotEqual(0, pushExitStatus, @"nik has pushed. I must merge");

[repo fetch];

S7ConfigMergeDriver *configMergeDriver = [S7ConfigMergeDriver new];

[configMergeDriver setResolveConflictBlock:^S7ConflictResolutionOption(S7SubrepoDescription * _Nonnull ourVersion,
S7SubrepoDescription * _Nonnull theirVersion)
{
XCTAssertEqualObjects(ourVersion.path, @"Dependencies/ReaddleLib");

return S7ConflictResolutionOptionKeepConflict;
}];

const int mergeExitStatus = [configMergeDriver
mergeRepo:repo
baseConfig:baseConfig
ourConfig:ourConfig
theirConfig:niksConfig
saveResultToFilePath:S7ConfigFileName];
XCTAssertNotEqual(0, mergeExitStatus);

S7Config *actualConfig = [[S7Config alloc] initWithContentsOfFile:S7ConfigFileName];

S7Config *expectedConfig = [[S7Config alloc] initWithSubrepoDescriptions:@[
[[S7SubrepoDescription alloc]
initWithPath:@"Dependencies/RDSFTP"
url:self.env.githubRDSFTPRepo.absolutePath
revision:sftp_niks_Revision
branch:@"master"],

[[S7SubrepoDescription alloc]
initWithPath:@"Dependencies/RDPDFKit"
url:self.env.githubRDPDFKitRepo.absolutePath
revision:pdfkit_pasteys_Revision
branch:@"master"],

[[S7SubrepoDescriptionConflict alloc]
initWithOurVersion:[[S7SubrepoDescription alloc]
initWithPath:@"Dependencies/ReaddleLib"
url:self.env.githubReaddleLibRepo.absolutePath
revision:readdleLib_pasteys_Revision
branch:@"master"]
theirVersion:[[S7SubrepoDescription alloc]
initWithPath:@"Dependencies/ReaddleLib"
url:self.env.githubReaddleLibRepo.absolutePath
revision:readdleLib_niks_Revision
branch:@"master"]]
]];

XCTAssertEqualObjects(actualConfig, expectedConfig);

S7Config *controlConfig = [[S7Config alloc] initWithContentsOfFile:S7ControlFileName];
XCTAssertNotNil(controlConfig);
XCTAssertEqualObjects(actualConfig, controlConfig);
}];
}

- (void)testBothSideUpdateSubrepoToDifferentRevisionSameFileSubrepoConflictResolution_Merge {
__block S7Config *baseConfig = nil;
__block NSString *readdleLib_initialRevision = nil;
Expand Down
Loading

0 comments on commit 5ae1204

Please sign in to comment.