Example #1
0
        // Git doesn't track empty directories, so this method
        // fills them all with a hidden empty file.
        //
        // It also prevents git repositories from becoming
        // git submodules by renaming the .git/HEAD file
        private void PrepareDirectories(string path)
        {
            try {
                foreach (string child_path in Directory.GetDirectories(path))
                {
                    if (SparkleHelpers.IsSymlink(child_path))
                    {
                        continue;
                    }

                    if (child_path.EndsWith(".git"))
                    {
                        if (child_path.Equals(Path.Combine(LocalPath, ".git")))
                        {
                            continue;
                        }

                        string HEAD_file_path = Path.Combine(child_path, "HEAD");

                        if (File.Exists(HEAD_file_path))
                        {
                            File.Move(HEAD_file_path, HEAD_file_path + ".backup");
                            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Renamed " + HEAD_file_path);
                        }

                        continue;
                    }

                    PrepareDirectories(child_path);
                }

                if (Directory.GetFiles(path).Length == 0 &&
                    Directory.GetDirectories(path).Length == 0 &&
                    !path.Equals(LocalPath))
                {
                    if (!File.Exists(Path.Combine(path, ".empty")))
                    {
                        try {
                            File.WriteAllText(Path.Combine(path, ".empty"), "I'm a folder!");
                            File.SetAttributes(Path.Combine(path, ".empty"), FileAttributes.Hidden);
                        } catch {
                            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Failed adding empty folder " + path);
                        }
                    }
                }
            } catch (IOException e) {
                SparkleHelpers.DebugInfo("Git", "Failed preparing directory: " + e.Message);
            }
        }