libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Remove tag

Open iceicys opened this issue 4 years ago • 1 comments

How do I remove a tag and push the removed tag to a remote repo?

I've tried the following but have been unsuccessful, I can query the tags in the repos but I haven't found a way to remove tags and push to the remote.

` using System; using System.Collections.Generic; using System.IO; using LibGit2Sharp;

namespace GitTagging { class Program { static void Main(string[] args) { Console.WriteLine("Remove Tags");

        using (var repo = new Repository("C:\\src\\repo\\.git"))
        {
            var allTags = repo.Tags.ToList();
            var tagnames = new List<string>();
            foreach (var item in allTags)
            {
                tagnames.Add(item.FriendlyName);
            }

            StreamWriter file = new System.IO.StreamWriter("C:\\src\\tags.txt");
            foreach (string line in tagnames)
                file.WriteLine(line);
            file.Close();


            var tagstodelete = File.ReadAllLines("C:\\src\\tags.txt");
            var logList = new List<string>(tagstodelete);
            foreach (var item in logList)
            {
                repo.Tags.Remove(item);
                Remote remote = repo.Remotes["origin"];
                PushResult pushResult = repo.Network.Push(remote, ":refs/tags/" + item, credentialsLibGit2Sharp);
            }

        Console.ReadLine();
    }
}

}

`

iceicys avatar Feb 04 '21 20:02 iceicys

I'm using ssh for our git server so I can't verify anything about repo.Network.Push.

I 've resigned to using a regular C# Process approach. I still use libsharp for anything else that works, but unti there's feature parity, at least for core stuff, I'll just sprinkle some Process calls.

NPatch avatar Feb 20 '21 22:02 NPatch