From d0244e0da66ae05d8479a22c7e9edc4cb2939bbe Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 14 Sep 2011 19:30:17 +0200 Subject: [PATCH] Allow empty folders to be added by putting a hidden file in each of them before committing --- SparkleLib/Git/SparkleRepoGit.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index a29cfc48..6ce939c0 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -165,6 +165,8 @@ namespace SparkleLib { public override bool AnyDifferences { get { + FillEmptyDirectories (LocalPath); + SparkleGit git = new SparkleGit (LocalPath, "status --porcelain"); git.Start (); @@ -509,6 +511,22 @@ namespace SparkleLib { } + // Git doesn't track empty directories, so this method + // fills them all with a hidden empty file + private void FillEmptyDirectories (string path) + { + foreach (string child_path in Directory.GetDirectories (path)) { + if (path.EndsWith (".git") || path.EndsWith (".notes")) + continue; + + FillEmptyDirectories (child_path); + } + + if (Directory.GetFiles (path).Length == 0) + File.Create (Path.Combine (path, ".empty")); + } + + // Creates a pretty commit message based on what has changed private string FormatCommitMessage () {