MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / analyseRemoteStatus

Function analyseRemoteStatus

plugins/vcs/Algorithm.h:57–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55};
56
57inline RemoteStatus analyseRemoteStatus(const std::shared_ptr<Repository>& repository)
58{
59 auto mapPath = repository->getRepositoryRelativePath(GlobalMapModule().getMapName());
60
61 if (mapPath.empty() || !repository->getHead())
62 {
63 return RemoteStatus{ 0, 0, _("-") };
64 }
65
66 if (!repository->getHead()->getUpstream())
67 {
68 return RemoteStatus{ 0, 0, _("No tracked remote"), RequiredMergeStrategy::NoMergeRequired };
69 }
70
71 auto status = repository->getSyncStatusOfBranch(*repository->getHead());
72
73 if (repository->mergeIsInProgress())
74 {
75 return RemoteStatus{ status.localCommitsAhead, status.remoteCommitsAhead,
76 _("Merge in progress"), RequiredMergeStrategy::MergeAlreadyInProgress };
77 }
78
79 auto mapFileHasUncommittedChanges = repository->fileHasUncommittedChanges(mapPath);
80
81 if (status.remoteCommitsAhead == 0)
82 {
83 return status.localCommitsAhead == 0 ?
84 RemoteStatus{ status.localCommitsAhead, 0, _("Up to date"), RequiredMergeStrategy::NoMergeRequired } :
85 RemoteStatus{ status.localCommitsAhead, 0, _("Pending Upload"), RequiredMergeStrategy::JustPush };
86 }
87 else if (status.localCommitsAhead == 0 && !mapFileHasUncommittedChanges)
88 {
89 // No local commits and no uncommitted changes, we can fast-forward
90 return RemoteStatus{ 0, status.remoteCommitsAhead, _("Integrate"), RequiredMergeStrategy::FastForward };
91 }
92
93 // Check the incoming commits for modifications of the loaded map
94 auto head = repository->getHead();
95 auto upstream = head->getUpstream();
96
97 // Find the merge base for this ref and its upstream
98 auto mergeBase = repository->findMergeBase(*head, *upstream);
99
100 auto remoteDiffAgainstBase = repository->getDiff(*upstream, *mergeBase);
101
102 bool remoteDiffContainsMap = remoteDiffAgainstBase->containsFile(mapPath);
103
104 if (!remoteDiffContainsMap)
105 {
106 // Remote didn't change the map, we can integrate it without conflicting the loaded map
107 return RemoteStatus{ status.localCommitsAhead, status.remoteCommitsAhead, _("Integrate"),
108 status.localCommitsAhead == 0 ? RequiredMergeStrategy::FastForward : RequiredMergeStrategy::MergeRecursively };
109 }
110
111 if (mapFileHasUncommittedChanges)
112 {
113 return RemoteStatus{ status.localCommitsAhead, status.remoteCommitsAhead, _("Commit, then integrate "),
114 RequiredMergeStrategy::MergeMapWithUncommittedChanges };

Callers 6

syncWithRemoteFunction · 0.85
onMapEventMethod · 0.85
performFetchMethod · 0.85
analyseRemoteStatusMethod · 0.85
performSyncMethod · 0.85
performCommitMethod · 0.85

Calls 12

getHeadMethod · 0.80
getUpstreamMethod · 0.80
getSyncStatusOfBranchMethod · 0.80
mergeIsInProgressMethod · 0.80
findMergeBaseMethod · 0.80
getDiffMethod · 0.80
_Function · 0.50
getMapNameMethod · 0.45
emptyMethod · 0.45
containsFileMethod · 0.45

Tested by

no test coverage detected