Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (maint) Corrected whitespace
  (GH-1689) Delete packaging scripts before upgrade
  (doc) fix grammar in scripting guidelines
  (doc) add don't use nupkg to scripting guidelines
  (maint) fix typo
  (GH-1602) exit 2 on items outdated
  (doc) add step for rebasing prior to merging
  (GH-1614) Quote source name if includes pipe
  • Loading branch information
ferventcoder committed Mar 13, 2019
2 parents faaf3e5 + cb2799b commit 98f8053
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions COMMITTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Because we ask contributors to target master, sometimes a fix/enhancement may ne
* `build.bat` - build and test
* Any additional changes or testing here.
* `git checkout stable`
* `git fetch upstream` - if this pulls anything, make sure to also run `git rebase upstream/stable` prior to merging or you will lose the merge commit.
* `git merge pr<github_pull_id> --log --no-ff`
* `git branch -d pr<github_pull_id>`
* `git checkout master`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,12 @@ shortcut commands like `cinst` or `cup`.
`choco source list`, where `source` is the command and `list` is the
subcommand.
* Typically the subject comes next. If installing packages, the
subject would be the package names. e.g. `choco install pkg1 pkg2`.
subject would be the package names, e.g. `choco install pkg1 pkg2`.
* Never use 'nupkg' or point directly to a nupkg file UNLESS using
'choco push'. Use the source folder instead, e.g. `choco install
<package id> --source=""'c:\folder\with\package'""` instead of
`choco install DoNotDoThis.1.0.nupkg` or `choco install DoNotDoThis
--source=""'c:\folder\with\package\DoNotDoThis.1.0.nupkg'""`.
* Switches and parameters are called simply options. Options come
after the subject. e.g. `choco install pkg1 --debug --verbose`.
* Never use the force option (`--force`/`-f`) in scripts (or really
Expand All @@ -529,15 +534,15 @@ online or through `choco -?` /`choco [Command Name] -?`.
temporarily stop for input - the key here is temporarily. They will
continue without requiring any action after the temporary timeout
(typically 30 seconds).
* Full option names are prepended with two dashes. e.g. `--` or
* Full option names are prepended with two dashes, e.g. `--` or
`--debug --verbose --ignore-proxy`.
* When setting a value to an option, always put an equals (`=`)
between the name and the setting, e.g. `--source=""'local'""`.
* When setting a value to an option, always surround the value
properly with double quotes bookending apostrophes. e.g.
properly with double quotes bookending apostrophes, e.g.
`--source=""'internal_server'""`.
* If you are building PowerShell scripts, you can most likely just
simply use apostrophes surrounding option values e.g.
simply use apostrophes surrounding option values, e.g.
`--source='internal_server'`.
* Prefer upgrade to install in scripts. You can't `install` to a newer
version of something, but you can `choco upgrade` which will do both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public virtual IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration
else
{
this.Log().Info(() => "{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}".format_with(
source.Id,
source.Id.quote_if_pipe_found(),
source.Value,
source.Disabled.to_string(),
source.UserName.quote_if_pipe_found(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,29 +633,34 @@ Output is package name | current version | available version | pinned?

var output = config.RegularOutput;
config.RegularOutput = false;
var oudatedPackages = _nugetService.get_outdated(config);
var outdatedPackages = _nugetService.get_outdated(config);
config.RegularOutput = output;

if (config.RegularOutput)
{
var upgradeWarnings = oudatedPackages.Count(p => p.Value.Warning);
var upgradeWarnings = outdatedPackages.Count(p => p.Value.Warning);
this.Log().Warn(() => @"{0}{1} has determined {2} package(s) are outdated. {3}".format_with(
Environment.NewLine,
ApplicationParameters.Name,
oudatedPackages.Count(p => p.Value.Success && !p.Value.Inconclusive),
outdatedPackages.Count(p => p.Value.Success && !p.Value.Inconclusive),
upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings)
));

if (upgradeWarnings != 0)
{
this.Log().Warn(ChocolateyLoggers.Important, "Warnings:");
foreach (var warning in oudatedPackages.Where(p => p.Value.Warning).or_empty_list_if_null())
foreach (var warning in outdatedPackages.Where(p => p.Value.Warning).or_empty_list_if_null())
{
this.Log().Warn(ChocolateyLoggers.Important, " - {0}".format_with(warning.Value.Name));
}
}
}

if (outdatedPackages.Count != 0 && Environment.ExitCode == 0)
{
Environment.ExitCode = 2;
}

randomly_notify_about_pro_business(config);
}

Expand Down
31 changes: 28 additions & 3 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
var pkgInfo = _packageInfoService.get_package_information(installedPackage);
bool isPinned = pkgInfo.IsPinned;

// if the package is pinned and we are skipping pinned,
// if the package is pinned and we are skipping pinned,
// move on quickly
if (isPinned && config.OutdatedCommand.IgnorePinned)
{
Expand All @@ -918,7 +918,7 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
}

var latestPackage = find_package(packageName, null, config, repository);

if (latestPackage == null)
{
if (config.Features.IgnoreUnfoundPackagesOnUpgradeOutdated) continue;
Expand All @@ -933,7 +933,7 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
}

if (latestPackage.Version <= installedPackage.Version) continue;

var packageResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(latestPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, latestPackage.Id)));

string logMessage = "You have {0} v{1} installed. Version {2} is available based on your source(s).{3} Source(s): \"{4}\"".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, Environment.NewLine, config.Sources);
Expand Down Expand Up @@ -1146,6 +1146,8 @@ public virtual void backup_existing_version(ChocolateyConfiguration config, IPac
try
{
_fileSystem.copy_directory(backupLocation, pkgInstallPath, overwriteExisting: true);

remove_packaging_files_prior_to_upgrade(pkgInstallPath, config.CommandName);
}
catch (Exception ex)
{
Expand All @@ -1167,6 +1169,29 @@ process locking the folder or files. Please make sure nothing is
}
}

public virtual void remove_packaging_files_prior_to_upgrade(string directoryPath, string commandName)
{
if (commandName.to_lower() == "upgrade")
{
// Due to the way that Package Reducer works, there is a potential that a Chocolatey Packaging
// script could be incorrectly left in place during an upgrade operation. To guard against this,
// remove any Chocolatey Packaging scripts, which will then be restored by the new package, if
// they are still required
var filesToDelete = new List<string> {"chocolateyinstall", "chocolateyuninstall", "chocolateybeforemodify"};
var packagingScripts = _fileSystem.get_files(directoryPath, "*.ps1", SearchOption.AllDirectories)
.Where(p => filesToDelete.Contains(_fileSystem.get_file_name_without_extension(p).to_lower()));

foreach (var packagingScript in packagingScripts)
{
if (_fileSystem.file_exists(packagingScript))
{
this.Log().Debug("Deleting file {0}".format_with(packagingScript));
_fileSystem.delete_file(packagingScript);
}
}
}
}

public virtual void backup_changed_files(string packageInstallPath, ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo)
{
if (packageInfo == null || packageInfo.Package == null) return;
Expand Down

0 comments on commit 98f8053

Please sign in to comment.