From e9d45261bd72ef875f15635e3ec0fbe5989b31c3 Mon Sep 17 00:00:00 2001 From: Johannes Gilger Date: Sun, 29 Mar 2009 00:35:39 +0100 Subject: [PATCH] PBGitRepository: Display branch-name in window title This returns not only the name of the git-dir but also the current branch (or detached HEAD if no local branch is checked out). When reloading the refs (which also happens when checking-out using GitX), the displayName-method is called, updating the window-title. Signed-off-by: Johannes Gilger --- PBGitRepository.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/PBGitRepository.m b/PBGitRepository.m index 8ee97c9..b0de172 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -149,9 +149,17 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; // useless for display in the window title bar, so we show the directory above - (NSString*)displayName { - NSString* displayName = self.fileURL.path.lastPathComponent; - if ([displayName isEqualToString:@".git"]) - displayName = [self.fileURL.path stringByDeletingLastPathComponent].lastPathComponent; + NSString* dirName = self.fileURL.path.lastPathComponent; + if ([dirName isEqualToString:@".git"]) + dirName = [self.fileURL.path stringByDeletingLastPathComponent].lastPathComponent; + NSString* displayName; + if (![[PBGitRef refFromString:[[self headRef] simpleRef]] type]) { + displayName = [NSString stringWithFormat:@"%@ (detached HEAD)", dirName]; + } else { + displayName = [NSString stringWithFormat:@"%@ (branch: %@)", dirName, + [[self headRef] description]]; + } + return displayName; } @@ -236,6 +244,9 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; // Add an "All branches" option in the branches list [self addBranch:[PBGitRevSpecifier allBranchesRevSpec]]; [self addBranch:[PBGitRevSpecifier localBranchesRevSpec]]; + + [[[self windowController] window] setTitle:[self displayName]]; + return ret; }