2014-02-28 3 views
0

TFS 프로젝트의 (tf destroy) 가지를 찾아서 삭제하는 내장 된 방법이 있는데, 이는 오랫동안 비활성 상태였습니다. 어느 tfs 도구 또는 아마도 그것을 할 수있는 SQL 스크립트는 괜찮을 것입니다.비활성 tfs 분기를 찾아 삭제하십시오.

+0

대답은 긍정적이다,하지만 노력의 비트가 동작하는 예제를 설정하는 것입니다. –

+1

예, 일부 API를 사용하여 Warehouse 데이터베이스에 대해 SSRS를 사용할 수 있습니다. BI 개발자가 설정 했으므로 API 쿼리 이외의 세부 사항은 없습니다. 그러나 Main에 병합하기 전에 변경 내역에 대해 정말로 신경 쓰지 않는다면 tf destroy를 사용할 때주의해야합니다. – DaveShaw

답변

0

음, 모든 것은 여기에 코드를 게시, 누군가가 도움이 될 수도, 어렵지 않았다 :

private static string _tfLocation; //location of tf.exe 
private static string _tfProject; //our team project 

static void Main(string[] args) 
{ 
    _tfLocation = ConfigurationManager.AppSettings.Get("tfLocation"); 
    _tfProject = ConfigurationManager.AppSettings.Get("tfProject"); 
    var keepAliveBranches = ConfigurationManager.AppSettings.Get("keepAliveBranches").Split(',').ToList(); //branches that we keep anyway 
    var latestDate = DateTime.Now.AddMonths(-3); //we delete all branches that are older than 3 months 

    var folders = ExecuteCommand(string.Format("dir /folders \"{0}\"", _tfProject)); 
    var branches = folders.Split('\r', '\n').ToList(); 

    branches = branches.Where(b => !string.IsNullOrEmpty(b) && b.StartsWith("$")).Select(b => b.Remove(0, 1)).Skip(1).ToList(); 
    branches.ForEach(b => b = b.Remove(0, 1)); 

    foreach (var branch in branches) 
    { 
     if (keepAliveBranches.Contains(branch)) 
      continue; 

     //get latest changeset 
     var lastChangeset = ExecuteCommand(string.Format("history \"{0}/{1}\" /recursive /stopafter:1 /format:brief /sort:descending /noprompt", _tfProject, branch)); 
     var changesetDate = DateTime.Parse(Regex.Match(lastChangeset, @"\d{2}\.\d{2}\.\d{4}").Value); //get it's date 
     if (changesetDate < latestDate)       
      //destroy 
      ExecuteCommand(string.Format("destroy \"{0}/{1}\" /recursive /stopafter:1 /startcleanup /noprompt /silent", _tfProject, branch));    
    } 
} 

//execute console command and get results 
private static string ExecuteCommand(string command) 
{ 
    var process = new Process() 
    { 
     StartInfo = new ProcessStartInfo(_tfLocation) 
     { 
      UseShellExecute = false, 
      RedirectStandardOutput = true, 
      CreateNoWindow = true, 
      Arguments = command 
     }, 
    }; 
    process.Start(); 
    var result = process.StandardOutput.ReadToEnd(); 
    process.WaitForExit(); 

    return result; 
} 
2

할 수 있지만 TFS API를 사용하는 작은 프로그램을 작성하여 각 분기를 확인하고 사용하지 않는 프로그램을 삭제해야합니다.

간단한 C# 콘솔 앱을 사용할 수 있으며 TFS 공개 API가 매우 직관적이고 사용하기 쉽다는 것을 경험을 통해 알 수 있습니다. here으로 시작할 수 있습니다.

Here 님의 모든 브랜치를 표시하는 방법입니다.

1

사용하지 않는 분기에는 요소 수정 기록이 포함되어 있습니다. 사용하지 않는 분기는 분기를 writelock으로 삭제하고 떠나야합니다. 복구 된 공간은 중요하지 않습니다.

관련 문제