C#ã§ç¹å®ã®ãã¡ã¤ã«orãã©ã«ããgitignore対象ããå¤å®ãã(åä¸ãã¡ã¤ã«ç·¨)
C#ã¨ãããã»ã¨ãã©gitã³ãã³ãã®tipsã«ãªã£ã¦ãã¾ãã¾ãããç¹å®ã®ãã¡ã¤ã«/ãã©ã«ãã.gitignoreãã¡ã¤ã«ã«ããgit管ç対象å¤ã«ãªã£ã¦ãããã©ããã¯ããgit check-ignoreãã³ãã³ããå©ç¨ãã¦ä»¥ä¸ã®ãããªã½ã¼ã¹ã³ã¼ãã§èª¿ã¹ããã¨ãã§ãã¾ãã
string GitExePath = @"C:\Program Files\Git\cmd\git.exe"; /// <summary> /// git check-ignoreã³ãã³ãã§gitignore対象ã¨ãªã£ã¦ãããå¦ãã調ã¹ã /// </summary> /// <param name="fsi">調ã¹ã対象ã®ãã¡ã¤ã«(FileInfo)ã¾ãã¯ãã©ã«ã(DirectoryInfo)</param> /// <returns>trueï¼gitignoreæå®ãããfalseï¼gitignoreæå®ãªããnullï¼ããããgit管çå¤</returns> bool? IsGitIgnored(FileSystemInfo fsi) { ProcessStartInfo psInfo = new ProcessStartInfo(GitExePath); psInfo.Arguments = "check-ignore -q \"" + fsi.FullName + "\""; psInfo.CreateNoWindow = true; psInfo.UseShellExecute = false; psInfo.WorkingDirectory = (fsi is FileInfo ? (fsi as FileInfo).DirectoryName : fsi.FullName); using (Process p = Process.Start(psInfo)) { p.WaitForExit(); if (p.ExitCode == 0) { return true; // gitignore対象 } if (p.ExitCode == 1) { return false; // gitignore対象ã§ã¯ãªã } if (p.ExitCode == 128) { return null; // ããããgit管çå¤ã ã£ããç } // gitã³ãã³ãã®å¼ã³åºãã«å¤±æããå ´åãªã©ã¯çµäºã³ã¼ããããã«å¥(9009ãªã©)ã«ãªã throw new Exception(); };
git check-ignoreã³ãã³ãã¯ã«ã¬ã³ããã£ã¬ã¯ããªãgit管çä¸ã®ãã£ã¬ã¯ããªã«ãªã£ã¦ããªãã¨ãfatal: not a git repository (or any of the parent directories)ãã¨ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã®ã§ãWorkingDirectoryï¼Processå®è¡æã®ã«ã¬ã³ããã£ã¬ã¯ããªï¼ãæå®ãã¦å®è¡ããããã«ãã¦ãã¾ãã
ãªããgit check-ignoreã³ãã³ãã¯å®è¡çµæãè¿ã£ã¦ããã¾ã§ããªãå¾
ãããã¾ãï¼1åã®ã³ãã³ãå®è¡ã«ããããæ°åmSecç¨åº¦ãããã¾ãï¼ã
調ã¹ãããã¡ã¤ã«ã®æ°ãå°ãªããã°ãã®ã½ã¼ã¹ã®ããæ¹ã§ãå®ç¨ä¸ã®åé¡ã¯ãªãã§ããããããã¨ãã°ç¹å®ã®ãã£ã¬ã¯ããªå
ã®å
¨ãã¡ã¤ã«/ãµããã£ã¬ã¯ããªã®å
容ãä¸æ¬ã§èª¿ã¹ãã®ã§ããã° 別のアプローチ ãã¨ãã»ããããã§ãããã
â2019/02/02追è¨ï¼ç¶ãã®è¨äºãC#で特定フォルダ内のgitignore対象ではないファイル/サブフォルダを一括で取得する - hnx8のブログããæ¸ãã¾ããã
â2019/02/02追è¨ï¼ åä¸ãã¡ã¤ã«ã®gitignoreå¤å®å¦çãæ¹åããTresGrepã«çµã¿è¾¼ã¿ã¾ãããã「gitignore対象をSkip」フィルタ機能追加 - hnx8のブログãã«ã¦ã½ã¼ã¹ã³ã¼ãä¾ãå
¬éãã¦ãã¾ãã