I am trying to write a program in C# which can list out all conflicted files in a selected branch. The program will list out the username who committed last in conflicted file.
Actually we have multiple projects and a centralized project where multiple branch code merge using python AutoMerge server.
https://github.com/LivePersonInc/Auto-Merger
branch A Branch B Branch C Branch D Branch E Branch F
\ \ \ / / /
\ \ \ / / /
\ \ \ / / /
------------------------------------------
| AutoMerge Branch |
------------------------------------------
Currently I am facing lots of issue while finding the conflicts because even VS don't show all conflicted files on build. So I am looking for a solution how to start with. Any help will be appreciated.
I have written following method that will scan for all files having conflicted SVN keywords:
private async Task<bool> StartScan(string FolderPath)
{
try
{
if (string.IsNullOrEmpty(FolderPath))
{
MessageBox.Show("Please select path first");
return false;
}
if (!System.IO.Directory.Exists(FolderPath))
{
MessageBox.Show("Invalid Path.");
return false;
}
ConflictedFiles.Clear();
bool isUpdateSuccess = false;
//Here I want to take update of SVN Programatically
//?????????????????????????????????????????????????????
isUpdateSuccess = await TakeSVNUpdate(FolderPath);
//?????????????????????????????????????????????????????
//?????????????????????????????????????????????????????
if (!isUpdateSuccess)
return false;
buttonScan.Enabled = false;
buttonBrowse.Enabled = false;
txtPath.Enabled = false;
int validFilesScanCount = 0;
int irrelaventExtensions = 0;
int conflictedFilesCount = 0;
string[] ValidExtensions = { ".cs", ".csproj" };
string[] ConflictKeywords = { "<<<<<<< .mine", ">>>>>>>", "|||||||" };
string FileName = "";
string[] files = Directory.GetFiles(FolderPath, ".", SearchOption.AllDirectories).Where(d => !d.Contains(".svn")).Where(d => !d.Contains("\\bin\\Debug")).Where(d => !d.Contains("\\obj\\Debug")).Where(d => !d.Contains("\\.vs")).ToArray();
textBoxConflictedFiles.AppendText("==============================Conflicted Files Scan Start==============================\n" + Environment.NewLine);
foreach (var file in files)
{
lblScanningFiles.Text = file;
await Task.Delay(10);
string extension = Path.GetExtension(file);
if (!ValidExtensions.Contains(extension))
{
irrelaventExtensions++;
continue;
}
else
{
validFilesScanCount++;
string readText = File.ReadAllText(file);
var Isconflict = ConflictKeywords.Any(w => readText.Contains(w));
if (Isconflict)
{
FileName = file + Environment.NewLine;
conflictedFilesCount++;
textBoxConflictedFiles.AppendText(FileName + Environment.NewLine);
string LastCommitedBy_Revision = "";
//Here I want to check SVN Log Programatically
//?????????????????????????????????????????????????????
LastCommitedBy_Revision = CheckSVNLog(file);
//?????????????????????????????????????????????????????
if (!string.IsNullOrEmpty(LastCommitedBy_Revision))
ConflictedFiles.Add(file + " [ Last Commited By - " + LastCommitedBy_Revision + " ]");
}
}
}
if (conflictedFilesCount == 0)
{
textBoxConflictedFiles.AppendText("No Conflicts Found." + Environment.NewLine);
}
else
{
textBoxConflictedFiles.AppendText("==============================Conflicted Files Scan End==============================" + Environment.NewLine);
textBoxConflictedFiles.AppendText("======Conflicted Files Details======" + Environment.NewLine + Environment.NewLine);
foreach (string conflictedfile in ConflictedFiles)
{
textBoxConflictedFiles.AppendText(conflictedfile + Environment.NewLine + Environment.NewLine);
}
textBoxConflictedFiles.AppendText("Total Conflicted Files." + conflictedFilesCount + Environment.NewLine);
}
lblScanningFiles.Text = "Total Files Scanned " + validFilesScanCount;
}
catch (Exception ex)
{
textBoxConflictedFiles.AppendText(Environment.NewLine + "Scan Error.." + Environment.NewLine + ex.Message);
return false;
}
finally
{
buttonScan.Enabled = true;
buttonBrowse.Enabled = true;
txtPath.Enabled = true;
}
return true;
}
I need help to implement TakeSVNUpdate and CheckSVNLog Methods.
private async Task<bool> TakeSVNUpdate(string Path)
{
?????????
return boolean;
}
private string CheckSVNLog(string FilePath)
{
??????????
return LastCommitedByUserNameANDRevision ;
}
Any help will be appreciated.