Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Git merge error handling and AppVeyor build #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Installer/MakeInstallers.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@ECHO OFF

pushd %~dp0

set TMPOUTDIR=%~dp0%tmp_build

msbuild.exe /t:Build /p:Configuration=Release ^
/property:Platform="Any CPU" ^
/p:OutputPath="%TMPOUTDIR%" ^
"..\SCM_Notifier\SCM_Notifier.csproj"

if ERRORLEVEL 1 goto BUILDERROR

makensis /DTARGETDIR="%TMPOUTDIR%" Setup.nsi
goto OKEXIT

:BUILDERROR
echo Can't build project

:OKEXIT
@rd /S /Q "%TMPOUTDIR%" 2>nul
popd
138 changes: 138 additions & 0 deletions Installer/Setup.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
!include LogicLib.nsh
!include MUI2.nsh
!include nsProcess.nsh

!define APPNAME "SCM_Notifier"

!define BASE_DIR "${TARGETDIR}"
!define EXE_FILE_NAME "SCM_Notifier.exe"
!define PRIMARYASSEMBLY "${BASE_DIR}\${EXE_FILE_NAME}"

!define GEN_VERSIONHEADER "_version.nsi"
!system 'nsisiw.exe -i "${PRIMARYASSEMBLY}" -o ${GEN_VERSIONHEADER}'
!include /NONFATAL "${GEN_VERSIONHEADER}"

Name "${APPNAME} (${FILE_ARCHITECTURE})"

!if ${FILE_ARCHITECTURE} == "x86"
!define PROGDIR "$PROGRAMFILES"
!define FRAMEWORKDIR "Framework"
!else
!define PROGDIR "$PROGRAMFILES64"
!define FRAMEWORKDIR "Framework64"
!endif

!define OUTDIR "Target"

# todo: find proper ngen location from in registry
!define NGEN_PATH "$WINDIR\Microsoft.NET\${FRAMEWORKDIR}\v4.0.30319\ngen.exe"

# Uninstall key
!define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"

# Version information
!ifdef VI_PRODUCTIONVERSION
VIProductVersion "${VI_PRODUCTIONVERSION}"

!ifdef VI_FILEVERSION
VIAddVersionKey FileVersion "${VI_FILEVERSION}"
!endif

!ifdef VI_DESCRIPTION
VIAddVersionKey FileDescription "${VI_DESCRIPTION}"
!endif

!ifdef VI_COPYRIGHTS
VIAddVersionKey LegalCopyright "${VI_COPYRIGHTS}"
!endif
!endif

!define MUI_COMPONENTSPAGE_NODESC

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "German"

Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" \
"UninstallString"
StrCmp $R0 "" done

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"${APPNAME} is already installed. $\n$\nClick `OK` to remove the \
previous version or `Cancel` to cancel this upgrade." \
IDOK uninst
Abort

uninst:
ClearErrors
ExecWait '$R0'
IfErrors no_remove_uninstaller done
no_remove_uninstaller:
done:
FunctionEnd

!system 'md "${OUTDIR}"'
OutFile "${OUTDIR}\setup-${VI_PRODUCTIONVERSION}.exe"

InstallDir "${PROGDIR}\${APPNAME}"
InstallDirRegKey HKLM "Software\${APPNAME}" "Install_Dir"
RequestExecutionLevel admin
ShowInstDetails show

# Program files section
Section "Program files"
SectionIn RO
SetOutPath $INSTDIR
File /x *.pdb /x *.xml /x *.vshost.exe* "${BASE_DIR}\*.*"
WriteRegStr HKLM "${UNKEY}" "DisplayName" "${APPNAME}"
WriteRegStr HKLM "${UNKEY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "${UNKEY}" "NoModify" 1
WriteRegDWORD HKLM "${UNKEY}" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd

# Run at startup section
Section "Run at startup (create scheduler task)"
ExecWait '"$INSTDIR\${EXE_FILE_NAME}" /installtask'
SectionEnd

# NGEN installation section
Section "NGEN installation (faster startup)"
AddSize 200
nsExec::ExecToLog '${NGEN_PATH} install "$INSTDIR\${EXE_FILE_NAME}"'
SectionEnd

# Launch After Install section
Section "Launch after install"
ExecShell "" "$INSTDIR\${EXE_FILE_NAME}"
SectionEnd

# Run at startup section
Section "Add program shortcuts to start menu"
CreateShortCut "$SMPROGRAMS\${APPNAME}.lnk" "$INSTDIR\${EXE_FILE_NAME}"
SectionEnd

# Uninstall section
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
DeleteRegKey HKLM "SOFTWARE\${APPNAME}"
nsExec::ExecToLog '"$INSTDIR\${EXE_FILE_NAME}" /removetask'
${nsProcess::CloseProcess} "${EXE_FILE_NAME}" $R0
Delete "$INSTDIR\uninstall.exe"
Delete "$SMPROGRAMS\${APPNAME}.lnk"
RMDir /r "$INSTDIR"
${nsProcess::Unload}
nsExec::ExecToLog '${NGEN_PATH} uninstall ${APPNAME}'
SectionEnd
Binary file added Installer/nsisiw.exe
Binary file not shown.
53 changes: 28 additions & 25 deletions SCM_Notifier/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
//

using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace pocorall.SCM_Notifier
{
Expand All @@ -35,13 +30,11 @@ public class GitRepository : ScmRepository

static GitRepository()
{
regexUpToDate = new Regex(@"^\s=\s\[up to date\]\s.+?\s->\s.+$",RegexOptions.Compiled);
regexUpToDate = new Regex(@"^\s=\s\[up to date\]\s.+?\s->\s.+$", RegexOptions.Compiled);
}


public static bool IsGitRepositoryDir(string dir)
{

if (string.IsNullOrEmpty(dir))
return false;
dir = System.IO.Path.Combine(dir, ".git");
Expand All @@ -54,13 +47,12 @@ public static bool IsGitRepositoryDir(string dir)

public GitRepository(string path, PathType type = ScmRepository.PathType.Directory) : base("Git", path, type)
{

}

protected override int GetRepositoryRevision(string binaryPath, string path, string arg)
{
string arguments = String.Format("info --non-interactive --xml \"{0}\" -r {1}", path, arg);
ExecuteResult er = ExecuteProcess(binaryPath, path, arguments, true, false);
ExecuteResult er = ExecuteProcess(binaryPath, path, arguments, true, false);

try
{
Expand Down Expand Up @@ -118,14 +110,14 @@ public override void Update(bool updateAll)
arguments = String.Format("pull {0}", Path);

ExecuteResult er = ExecuteProcess(Config.GitUIPath, Path, arguments, true, false);
string d = ( er.processOutput);
string d = (er.processOutput);
}

private bool isModified(string response)
{
return !(response.Contains("othing added to commit") || response.Contains("othing to commit"));
}

private bool IsTortoiseGit(string path)
{
return path.EndsWith("TortoiseGitProc.exe");
Expand All @@ -151,7 +143,7 @@ public override void Commit()
{
if (this.IsGitExtensions(Config.GitUIPath))
arguments = String.Format("commit {0}", Path);
else
else
arguments = String.Format("/command:commit /path:\"{0}\" /notempfile", Path);
}
er = ExecuteProcess(Config.GitUIPath, null, arguments, false, false);
Expand All @@ -172,14 +164,14 @@ private string ResolveCurrentBranchName(string data)
{
result = strings[1].Trim();

//
//
int startPosition = result.IndexOf(CONST_STATUS_MARKER);
if (startPosition > 0)
{
result = result.Remove(0, startPosition + CONST_STATUS_MARKER.Length);
}

//
//
startPosition = result.IndexOf(CONST_ORIGIN_MARKER);
if (startPosition > 0)
{
Expand All @@ -202,15 +194,20 @@ public override ScmRepositoryStatusEx GetStatus()
try
{
ExecuteResult er = ExecuteProcess(Config.GitPath, path, "fetch --all --dry-run -v", true, true);
if (er.processError.Contains("Could not fetch"))

// Strip info: detecting host provider from process output
string processError = Regex.Replace(er.processError, @"info:.+\n", "", RegexOptions.IgnoreCase);

if (processError.Contains("Could not fetch"))
{
return new ScmRepositoryStatusEx() { status = ScmRepositoryStatus.Error };
}

ScmRepositoryStatusEx result = new ScmRepositoryStatusEx();
result.branchName = ResolveCurrentBranchName(er.processError);

bool needUpdate = this.IsNeedUpdate(er.processError);
result.branchName = ResolveCurrentBranchName(processError);

bool needUpdate = this.IsNeedUpdate(processError);

string arguments = String.Format("status -u \"{0}\"", path);
er = ExecuteProcess(Config.GitPath, path, arguments, true, true);
Expand All @@ -227,11 +224,10 @@ public override ScmRepositoryStatusEx GetStatus()
if (er.processOutput.Contains("branch is ahead of") || er.processOutput.Contains("Changed but not updated") || er.processOutput.Contains("Changes not staged for commit")
|| er.processOutput.Contains("Changes to be committed"))
{
result.status = needUpdate? ScmRepositoryStatus.NeedUpdate_Modified: ScmRepositoryStatus.UpToDate_Modified;
result.status = needUpdate ? ScmRepositoryStatus.NeedUpdate_Modified : ScmRepositoryStatus.UpToDate_Modified;
return result;
}
else
if (!isModified(er.processOutput))
else if (!isModified(er.processOutput))
{
result.status = needUpdate ? ScmRepositoryStatus.NeedUpdate : ScmRepositoryStatus.UpToDate;
return result;
Expand All @@ -253,9 +249,16 @@ private bool IsNeedUpdate(string str)
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.StartsWith("From") || line.StartsWith("POST git-upload-pack")) continue;
if (!regexUpToDate.IsMatch(line)) return true;
{
if (line.StartsWith("From") || line.StartsWith("Fetching") || line.StartsWith("POST git-upload-pack"))
{
continue;
}

if (!regexUpToDate.IsMatch(line))
{
return true;
}
}
}
return false;
Expand Down
Loading