Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into FetchOnlyWhenNece…
Browse files Browse the repository at this point in the history
…ssary
  • Loading branch information
davidwengier committed Dec 12, 2018
2 parents 6f57bce + 68047a7 commit f8e0ed8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GitPullRequest.Services/AzureDevOpsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override IDictionary<string, string> GetReferences(IRepository repo, s
}

// Now that we know the data is available we can go through and reset our PR refs to point to one commit before the merge commit
var pullRequestRefs = remoteRefs.Where(k => k.Key.StartsWith("refs/pull/", StringComparison.OrdinalIgnoreCase)).ToList();
var pullRequestRefs = remoteRefs.Where(k => FindPullRequestForCanonicalName(k.Key) != -1).ToList();
foreach (var kvp in pullRequestRefs)
{
// Get the commit at HEAD^1 as Azure DevOps automatically adds a merge commit on the server
Expand Down
2 changes: 1 addition & 1 deletion GitPullRequest.Services/GitPullRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IDictionary<string, RemoteRepository> GetGitRepositories(IRepository repo
{
var isDeleted = false;
string sha = null;
if (branch.IsTracking)
if (branch.IsTracking || branch.IsRemote)
{
var gitRepository = gitRepositories[branch.RemoteName];
var references = gitRepository.References;
Expand Down
11 changes: 9 additions & 2 deletions GitPullRequest.Services/LibGitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ public IDictionary<string, string> ListReferences(IRepository repo, string remot

public void Fetch(IRepository repo, string remoteName, string[] refSpecs, bool prune)
{
var credentialsHandler = CreateCredentialsHandler(repo, remoteName);
ProgressHandler progressHandler = text =>
{
Console.Write(text);
return true;
};

repo.Network.Fetch(remoteName, refSpecs, new FetchOptions
{
CredentialsProvider = CreateCredentialsHandler(repo, remoteName),
Prune = prune

This comment has been minimized.

Copy link
@jcansdale

jcansdale Dec 12, 2018

Owner

Oops, bad merge. Prune = prune shouldn't have been removed!

CredentialsProvider = credentialsHandler,
OnProgress = progressHandler
});
}

Expand Down
2 changes: 1 addition & 1 deletion GitPullRequest/GitPullRequest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<Version>1.0.10</Version>
<Version>1.0.11</Version>

<LangVersion>7.3</LangVersion>

Expand Down
21 changes: 15 additions & 6 deletions GitPullRequest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static int Main(string[] args)
[Option("--list", Description = "List local branches with associated pull requests")]
public bool List { get; }

[Option("--all", Description = "List all branches with associated pull requests")]
public bool All { get; }
[Option("--remote", Description = "List remote branches with associated pull requests")]
public string Remote { get; }

[Option("--prune", Description = "Remove pull requests with deleted remote branches")]
public bool Prune { get; }
Expand Down Expand Up @@ -55,9 +55,9 @@ void OnExecute()

try
{
if (List || All)
if (List || Remote != null)
{
ListBranches(service, repo);
ListBranches(service, repo, Remote);
return;
}

Expand Down Expand Up @@ -110,11 +110,11 @@ void BrowsePullRequest(GitPullRequestService service, Repository repo)
Console.WriteLine("Couldn't find pull request or remote branch");
}

void ListBranches(GitPullRequestService service, Repository repo)
void ListBranches(GitPullRequestService service, Repository repo, string remoteName)
{
var gitRepositories = service.GetGitRepositories(repo);
var prs = repo.Branches
.Where(b => All || !b.IsRemote)
.Where(b => remoteName == null && !b.IsRemote || remoteName != null && b.IsRemote && b.RemoteName == remoteName)
.SelectMany(b => service.FindPullRequests(gitRepositories, b), (b, p) => (Branch: b, PullRequest: p))
.Where(bp => PullRequestNumber == 0 || bp.PullRequest.Number == PullRequestNumber)
.OrderBy(bp => bp.Branch.IsRemote)
Expand All @@ -135,6 +135,15 @@ void ListBranches(GitPullRequestService service, Repository repo)

foreach (var bp in prs)
{
if (remoteName != null &&
bp.Branch.IsRemote &&
bp.Branch.RemoteName != bp.PullRequest.Repository.RemoteName &&
bp.PullRequest.Repository.References.ContainsKey(bp.Branch.UpstreamBranchCanonicalName))
{
// Ignore branches forked from parent repository
continue;
}

var isHead = bp.Branch.IsCurrentRepositoryHead ? "* " : " ";
var remotePrefix = bp.PullRequest.Repository.RemoteName != "origin" ? bp.PullRequest.Repository.RemoteName : "";

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To browse or create a pull request:
git pr
```

If there is a pull request associated with the current branch is will be opened in the
If there is a pull request associated with the current branch it will be opened in the
default browser. If there is a remote branch but no pull request, the compare/create pull
request page will be opened.

Expand Down

0 comments on commit f8e0ed8

Please sign in to comment.