Skip to content

Commit

Permalink
#43 Cache Stash information
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Jun 21, 2018
1 parent 61b8775 commit 38b8ee3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion TGit/Helpers/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ public EnvHelper(DTE dte)
_cache = new MemoryCache("TGIT");
}

/// <summary>
/// Check if GitFlow is initialized
/// </summary>
/// <remarks>Getting the actual flow config is cached for 1m</remarks>
/// <returns></returns>
public bool IsGitFlow()
{
var gitConfig = GetGitConfig();
return !string.IsNullOrEmpty(gitConfig.MasterBranch);
}

/// <summary>
/// Get the Git config
/// </summary>
/// <remarks>Cached for 1m</remarks>
/// <returns></returns>
public GitConfig GetGitConfig()
{
if (_cache.Contains("GitConfig"))
Expand Down Expand Up @@ -59,9 +69,21 @@ public string GetSolutionDir()
return solutionDir;
}

/// <summary>
/// Do we have any stashes available
/// </summary>
/// <remarks>Cached for 1m</remarks>
/// <returns></returns>
public bool HasStash()
{
return ProcessHelper.StartProcessGit(this, "stash list");
if (_cache.Contains("HasStash"))
{
return bool.Parse(_cache.Get("HasStash").ToString());
}

var hasStash = ProcessHelper.StartProcessGit(this, "stash list");
_cache.Set("HasStash", hasStash, DateTimeOffset.Now.AddMinutes(1));
return hasStash;
}

/// <summary>
Expand Down Expand Up @@ -104,8 +126,18 @@ public string GetGit()
return git;
}

/// <summary>
/// Check if we have a path to a solution directory
/// </summary>
/// <remarks>Actual solution dir path is cached for 30s</remarks>
/// <returns></returns>
public bool HasSolutionDir() => !string.IsNullOrEmpty(GetSolutionDir());

/// <summary>
/// Get the Git branch name eg. 'feature/tgit'
/// </summary>
/// <remarks>Cached for 15s</remarks>
/// <returns></returns>
private string GetBranchName()
{
if (_cache.Contains("BranchName"))
Expand All @@ -121,6 +153,12 @@ private string GetBranchName()
return branchName;
}

/// <summary>
/// Check if a branch name starts with a given value
/// </summary>
/// <remarks>Actual branch name is cached for 15s</remarks>
/// <param name="name"></param>
/// <returns></returns>
public bool BranchNameStartsWith(string name) => GetBranchName().StartsWith(name);
}
}

0 comments on commit 38b8ee3

Please sign in to comment.