View Javadoc
1   /*
2    * Copyright (C) 2010, Marc Strapetz <marc.strapetz@syntevo.com>
3    * Copyright (C) 2012-2013, Robin Rosenberg and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  package org.eclipse.jgit.treewalk;
12  
13  import org.eclipse.jgit.lib.Config;
14  import org.eclipse.jgit.lib.Config.SectionParser;
15  import org.eclipse.jgit.lib.ConfigConstants;
16  import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
17  import org.eclipse.jgit.lib.CoreConfig.CheckStat;
18  import org.eclipse.jgit.lib.CoreConfig.EOL;
19  import org.eclipse.jgit.lib.CoreConfig.HideDotFiles;
20  import org.eclipse.jgit.lib.CoreConfig.SymLinks;
21  
22  /**
23   * Options used by the {@link org.eclipse.jgit.treewalk.WorkingTreeIterator}.
24   */
25  public class WorkingTreeOptions {
26  	/** Key for {@link Config#get(SectionParser)}. */
27  	public static final Config.SectionParser<WorkingTreeOptions> KEY =
28  			WorkingTreeOptions::new;
29  
30  	private final boolean fileMode;
31  
32  	private final AutoCRLF autoCRLF;
33  
34  	private final EOL eol;
35  
36  	private final CheckStat checkStat;
37  
38  	private final SymLinks symlinks;
39  
40  	private final HideDotFiles hideDotFiles;
41  
42  	private final boolean dirNoGitLinks;
43  
44  	private WorkingTreeOptions(Config rc) {
45  		fileMode = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
46  				ConfigConstants.CONFIG_KEY_FILEMODE, true);
47  		autoCRLF = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
48  				ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
49  		eol = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
50  				ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE);
51  		checkStat = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
52  				ConfigConstants.CONFIG_KEY_CHECKSTAT, CheckStat.DEFAULT);
53  		symlinks = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
54  				ConfigConstants.CONFIG_KEY_SYMLINKS, SymLinks.TRUE);
55  		hideDotFiles = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
56  				ConfigConstants.CONFIG_KEY_HIDEDOTFILES,
57  				HideDotFiles.DOTGITONLY);
58  		dirNoGitLinks = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
59  				ConfigConstants.CONFIG_KEY_DIRNOGITLINKS,
60  				false);
61  	}
62  
63  	/** @return true if the execute bit on working files should be trusted. */
64  	/**
65  	 * Whether the execute bit on working files should be trusted.
66  	 *
67  	 * @return {@code true} if the execute bit on working files should be
68  	 *         trusted.
69  	 */
70  	public boolean isFileMode() {
71  		return fileMode;
72  	}
73  
74  	/**
75  	 * Get automatic CRLF conversion configuration.
76  	 *
77  	 * @return how automatic CRLF conversion has been configured.
78  	 */
79  	public AutoCRLF getAutoCRLF() {
80  		return autoCRLF;
81  	}
82  
83  	/**
84  	 * Get how text line endings should be normalized.
85  	 *
86  	 * @return how text line endings should be normalized.
87  	 * @since 4.3
88  	 */
89  	public EOL getEOL() {
90  		return eol;
91  	}
92  
93  	/**
94  	 * Get how stat data is compared.
95  	 *
96  	 * @return how stat data is compared.
97  	 * @since 3.0
98  	 */
99  	public CheckStat getCheckStat() {
100 		return checkStat;
101 	}
102 
103 	/**
104 	 * Get how we handle symbolic links
105 	 *
106 	 * @return how we handle symbolic links
107 	 * @since 3.3
108 	 */
109 	public SymLinks getSymLinks() {
110 		return symlinks;
111 	}
112 
113 	/**
114 	 * Get how we create '.'-files (on Windows)
115 	 *
116 	 * @return how we create '.'-files (on Windows)
117 	 * @since 3.5
118 	 */
119 	public HideDotFiles getHideDotFiles() {
120 		return hideDotFiles;
121 	}
122 
123 	/**
124 	 * Whether or not we treat nested repos as directories.
125 	 *
126 	 * @return whether or not we treat nested repos as directories. If true,
127 	 *         folders containing .git entries will not be treated as gitlinks.
128 	 * @since 4.3
129 	 */
130 	public boolean isDirNoGitLinks() { return dirNoGitLinks; }
131 }