Skip to content

Commit b531ef3

Browse files
committed
code cleanup
1 parent 6ea8b4c commit b531ef3

File tree

2 files changed

+79
-68
lines changed

2 files changed

+79
-68
lines changed

src/GitVersionCore/Helpers/GitRepositoryHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static void AddMissingRefSpecs(ILog log, IRepository repo, Remote remote
193193
r => r.FetchRefSpecs.Add(allBranchesFetchRefSpec));
194194
}
195195

196-
private static void CreateFakeBranchPointingAtThePullRequestTip(ILog log, Repository repo, AuthenticationInfo authentication)
196+
private static void CreateFakeBranchPointingAtThePullRequestTip(ILog log, IRepository repo, AuthenticationInfo authentication)
197197
{
198198
var remote = repo.Network.Remotes.Single();
199199

@@ -262,7 +262,7 @@ private static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(IRepos
262262
return repo.Network.ListReferences(remote).Select(r => r.ResolveToDirectReference());
263263
}
264264

265-
private static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(ILog log, Repository repo, string remoteName)
265+
private static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(ILog log, IRepository repo, string remoteName)
266266
{
267267
var prefix = $"refs/remotes/{remoteName}/";
268268
var remoteHeadCanonicalName = $"{prefix}HEAD";

src/GitVersionExe/GitVersionExecutor.cs

Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -50,71 +50,7 @@ private int VerifyArgumentsAndRun(Arguments arguments)
5050
{
5151
try
5252
{
53-
if (arguments == null)
54-
{
55-
helpWriter.Write();
56-
return 1;
57-
}
58-
var targetPath = arguments.TargetPath;
59-
60-
if (arguments.IsVersion)
61-
{
62-
var assembly = Assembly.GetExecutingAssembly();
63-
versionWriter.Write(assembly);
64-
return 0;
65-
}
66-
67-
if (arguments.IsHelp)
68-
{
69-
helpWriter.Write();
70-
return 0;
71-
}
72-
73-
if (arguments.Diag)
74-
{
75-
arguments.NoCache = true;
76-
arguments.Output.Add(OutputType.BuildServer);
77-
}
78-
79-
#pragma warning disable CS0612 // Type or member is obsolete
80-
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
81-
#pragma warning restore CS0612 // Type or member is obsolete
82-
{
83-
arguments.Output.Add(OutputType.BuildServer);
84-
}
85-
86-
var buildServer = buildServerResolver.Resolve();
87-
arguments.NoFetch = arguments.NoFetch || buildServer != null && buildServer.PreventFetch();
88-
89-
ConfigureLogging(arguments, log);
90-
91-
if (arguments.Diag)
92-
{
93-
log.Info("Dumping commit graph: ");
94-
LibGitExtensions.DumpGraph(targetPath, mess => log.Info(mess), 100);
95-
}
96-
if (!Directory.Exists(targetPath))
97-
{
98-
log.Warning($"The working directory '{targetPath}' does not exist.");
99-
}
100-
else
101-
{
102-
log.Info("Working directory: " + targetPath);
103-
}
104-
105-
VerifyConfiguration();
106-
107-
if (arguments.Init)
108-
{
109-
configProvider.Init(targetPath);
110-
return 0;
111-
}
112-
if (arguments.ShowConfig)
113-
{
114-
var config = configProvider.Provide(targetPath);
115-
Console.WriteLine(config.ToString());
116-
return 0;
117-
}
53+
if (HandleNonMainCommand(arguments, out var exitCode)) return exitCode;
11854

11955
execCommand.Execute();
12056
}
@@ -148,9 +84,84 @@ private int VerifyArgumentsAndRun(Arguments arguments)
14884
return 0;
14985
}
15086

151-
private void VerifyConfiguration()
87+
private bool HandleNonMainCommand(Arguments arguments, out int exitCode)
15288
{
89+
if (arguments == null)
90+
{
91+
helpWriter.Write();
92+
exitCode = 1;
93+
return true;
94+
}
95+
96+
var targetPath = arguments.TargetPath;
97+
98+
if (arguments.IsVersion)
99+
{
100+
var assembly = Assembly.GetExecutingAssembly();
101+
versionWriter.Write(assembly);
102+
exitCode = 0;
103+
return true;
104+
}
105+
106+
if (arguments.IsHelp)
107+
{
108+
helpWriter.Write();
109+
exitCode = 0;
110+
return true;
111+
}
112+
113+
if (arguments.Diag)
114+
{
115+
arguments.NoCache = true;
116+
arguments.Output.Add(OutputType.BuildServer);
117+
}
118+
119+
#pragma warning disable CS0612 // Type or member is obsolete
120+
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
121+
#pragma warning restore CS0612 // Type or member is obsolete
122+
{
123+
arguments.Output.Add(OutputType.BuildServer);
124+
}
125+
126+
var buildServer = buildServerResolver.Resolve();
127+
arguments.NoFetch = arguments.NoFetch || buildServer != null && buildServer.PreventFetch();
128+
129+
ConfigureLogging(arguments, log);
130+
131+
if (arguments.Diag)
132+
{
133+
log.Info("Dumping commit graph: ");
134+
LibGitExtensions.DumpGraph(targetPath, mess => log.Info(mess), 100);
135+
}
136+
137+
if (!Directory.Exists(targetPath))
138+
{
139+
log.Warning($"The working directory '{targetPath}' does not exist.");
140+
}
141+
else
142+
{
143+
log.Info("Working directory: " + targetPath);
144+
}
145+
153146
configFileLocator.Verify(gitPreparer);
147+
148+
if (arguments.Init)
149+
{
150+
configProvider.Init(targetPath);
151+
exitCode = 0;
152+
return true;
153+
}
154+
155+
if (arguments.ShowConfig)
156+
{
157+
var config = configProvider.Provide(targetPath);
158+
Console.WriteLine(config.ToString());
159+
exitCode = 0;
160+
return true;
161+
}
162+
163+
exitCode = 0;
164+
return false;
154165
}
155166

156167
private static void ConfigureLogging(Arguments arguments, ILog log)

0 commit comments

Comments
 (0)