Skip to content

Commit e1ea015

Browse files
authored
Merge pull request #20 from cmarcusreid/upstreamGone
Report UpstreamGone. Resolves #19. UpstreamGone is set when a branch has no remote tracking reference but still has an upstream configured. This is similar to the git warning: Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup)
2 parents 399ae71 + 5169165 commit e1ea015

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ ipch/
7777
*.opensdf
7878
*.sdf
7979
*.cachefile
80+
*.VC.opendb
81+
*.VC.db
8082

8183
# Visual Studio profiler
8284
*.psess

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Retrieves current status information for the requested "Path".
3636
"State" : "",
3737
"Branch" : "master",
3838
"Upstream": "origin/master",
39+
"UpstreamGone": false,
3940
"AheadBy": 0,
4041
"BehindBy": 0,
4142
"IndexAdded": [],

ext/ReadDirectoryChanges/ide/ReadDirectoryChangesLib.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|Win32">
55
<Configuration>Debug</Configuration>
@@ -22,7 +22,7 @@
2222
<CharacterSet>Unicode</CharacterSet>
2323
<UseOfMfc>Dynamic</UseOfMfc>
2424
<UseOfAtl>Static</UseOfAtl>
25-
<PlatformToolset>v120</PlatformToolset>
25+
<PlatformToolset>v140</PlatformToolset>
2626
</PropertyGroup>
2727
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2828
<ConfigurationType>StaticLibrary</ConfigurationType>
@@ -31,7 +31,7 @@
3131
<CharacterSet>Unicode</CharacterSet>
3232
<UseOfMfc>Dynamic</UseOfMfc>
3333
<UseOfAtl>Static</UseOfAtl>
34-
<PlatformToolset>v120</PlatformToolset>
34+
<PlatformToolset>v140</PlatformToolset>
3535
</PropertyGroup>
3636
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3737
<ImportGroup Label="ExtensionSettings">

src/GitStatusCache/ide/GitStatusCache.vcxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|Win32">
55
<Configuration>Debug</Configuration>
@@ -19,13 +19,13 @@
1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
2020
<ConfigurationType>Application</ConfigurationType>
2121
<UseDebugLibraries>true</UseDebugLibraries>
22-
<PlatformToolset>v120</PlatformToolset>
22+
<PlatformToolset>v140</PlatformToolset>
2323
<CharacterSet>Unicode</CharacterSet>
2424
</PropertyGroup>
2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2626
<ConfigurationType>Application</ConfigurationType>
2727
<UseDebugLibraries>false</UseDebugLibraries>
28-
<PlatformToolset>v120</PlatformToolset>
28+
<PlatformToolset>v140</PlatformToolset>
2929
<WholeProgramOptimization>true</WholeProgramOptimization>
3030
<CharacterSet>Unicode</CharacterSet>
3131
</PropertyGroup>

src/GitStatusCache/src/Git.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ bool Git::GetRefStatus(Git::Status& status, UniqueGitRepository& repository)
219219
{
220220
status.Branch = std::string();
221221
status.Upstream = std::string();
222+
status.UpstreamGone = false;
222223
status.AheadBy = 0;
223224
status.BehindBy = 0;
224225

@@ -267,9 +268,40 @@ bool Git::GetRefStatus(Git::Status& status, UniqueGitRepository& repository)
267268
result = git_branch_upstream(&upstream.get(), head.get());
268269
if (result == GIT_ENOTFOUND)
269270
{
270-
Log("Git.GetRefStatus.NoUpstream", Severity::Spam)
271-
<< R"(Branch does not have a remote tracking reference. { "repositoryPath": ")" << status.RepositoryPath
272-
<< R"(", "localBranch": ")" << status.Branch << R"(" })";
271+
auto upstreamBranchName = git_buf{ 0 };
272+
auto upstreamBranchResult = git_branch_upstream_name(
273+
&upstreamBranchName,
274+
git_reference_owner(head.get()),
275+
git_reference_name(head.get()));
276+
277+
auto canBuildUpstream = false;
278+
if (upstreamBranchResult == GIT_OK)
279+
{
280+
Log("Git.GetRefStatus.UpstreamGone", Severity::Spam)
281+
<< R"(Branch has a configured upstream that is gone. { "repositoryPath": ")" << status.RepositoryPath
282+
<< R"(", "localBranch": ")" << status.Branch << R"(" })";
283+
status.UpstreamGone = true;
284+
canBuildUpstream = upstreamBranchName.ptr != nullptr && upstreamBranchName.size != 0;
285+
}
286+
287+
if (canBuildUpstream)
288+
{
289+
const auto patternToRemove = std::string("refs/remotes/");
290+
auto upstreamName = std::string(upstreamBranchName.ptr);
291+
auto patternPosition = upstreamName.find(patternToRemove);
292+
if (patternPosition == 0 && upstreamName.size() > patternToRemove.size())
293+
{
294+
upstreamName.erase(patternPosition, patternToRemove.size());
295+
}
296+
status.Upstream = upstreamName;
297+
}
298+
else
299+
{
300+
Log("Git.GetRefStatus.NoUpstream", Severity::Spam)
301+
<< R"(Branch does not have a remote tracking reference. { "repositoryPath": ")" << status.RepositoryPath
302+
<< R"(", "localBranch": ")" << status.Branch << R"(" })";
303+
}
304+
273305
return true;
274306
}
275307
else if (result != GIT_OK)

src/GitStatusCache/src/Git.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Git
2222

2323
std::string Branch;
2424
std::string Upstream;
25+
bool UpstreamGone = false;
2526
int AheadBy = 0;
2627
int BehindBy = 0;
2728

src/GitStatusCache/src/StatusController.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ StatusController::~StatusController()
3131
writer.String(value.c_str());
3232
}
3333

34+
/*static*/ void StatusController::AddBoolToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer, std::string&& name, bool value)
35+
{
36+
writer.String(name.c_str());
37+
writer.Bool(value);
38+
}
39+
3440
/*static*/ void StatusController::AddUintToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer, std::string&& name, uint32_t value)
3541
{
3642
writer.String(name.c_str());
@@ -122,6 +128,7 @@ std::string StatusController::GetStatus(const rapidjson::Document& document, con
122128
AddStringToJson(writer, "State", statusToReport.State.c_str());
123129
AddStringToJson(writer, "Branch", statusToReport.Branch.c_str());
124130
AddStringToJson(writer, "Upstream", statusToReport.Upstream.c_str());
131+
AddBoolToJson(writer, "UpstreamGone", statusToReport.UpstreamGone);
125132
AddUintToJson(writer, "AheadBy", statusToReport.AheadBy);
126133
AddUintToJson(writer, "BehindBy", statusToReport.BehindBy);
127134

src/GitStatusCache/src/StatusController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class StatusController : boost::noncopyable
3333
*/
3434
static void AddStringToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer, std::string&& name, std::string&& value);
3535

36+
/**
37+
* Adds bool to JSON response.
38+
*/
39+
static void AddBoolToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer, std::string&& name, bool value);
40+
3641
/**
3742
* Adds uint32_t to JSON response.
3843
*/

0 commit comments

Comments
 (0)