Вывод имени Git репозитория в Console - C#
Формулировка задачи:
Вопрос такой:
Вот код программы. Идёт запись имени коммита в файл WriteLine.txt.
Хотелось бы этот файл назвать именно так, как называется репозиторий. (wikicar). Не знаю как я могу это сделать, но попытаться можно.
Листинг программы
- using LibGit2Sharp;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- using (StreamWriter outputFile = new StreamWriter("WriteLines.txt", true))
- {
- var refer = Repository.ListRemoteReferences("https://github.com/VladislavsGeidans/wikicar.git").FirstOrDefault() as SymbolicReference;
- Console.WriteLine(refer.Target.TargetIdentifier);
- outputFile.WriteLine(refer.Target.TargetIdentifier);
- Console.ReadKey();
- }
- }
- }
- }
Решение задачи: «Вывод имени Git репозитория в Console»
textual
Листинг программы
- static string getRepoName(string url)
- {
- if (String.IsNullOrEmpty(url)) {
- Console.WriteLine("Das ist error");
- }
- int repoNameIndex = url.LastIndexOf('/') + 1;
- if (repoNameIndex == 0 || repoNameIndex == url.Length) {
- throw new FormatException("https://github.com/VladislavsGeidans/wikicar.git");
- }
- return url.Substring(repoNameIndex);
- }
- static void Main(string[] args)
- {
- string url = "https://github.com/VladislavsGeidans/wikicar.git";
- string repoName = getRepoName(url);
- Console.WriteLine("Repo name is {repoName}");
- Console.ReadKey();
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д