• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 11892982640

18 Nov 2024 01:01PM UTC coverage: 67.276% (-0.006%) from 67.282%
11892982640

Pull #702

github

web-flow
Merge 5b12a1574 into 2966a61ee
Pull Request #702: #81: Implement ToolCommandlet for Kubernetes

2461 of 3999 branches covered (61.54%)

Branch coverage included in aggregate %.

6406 of 9181 relevant lines covered (69.77%)

3.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
1
package com.devonfw.tools.ide.context;
2

3
import java.nio.file.Path;
4

5
import com.devonfw.tools.ide.cli.CliOfflineException;
6

7
/**
8
 * Interface for git commands with input and output of information for the user.
9
 */
10
public interface GitContext {
11

12
  /** The default git remote name. */
13
  String DEFAULT_REMOTE = "origin";
14

15
  /** The default git url of the settings repository for IDEasy developers */
16
  String DEFAULT_SETTINGS_GIT_URL = "https://github.com/devonfw/ide-settings.git";
17

18
  /** The name of the internal metadata folder of a git repository. */
19
  String GIT_FOLDER = ".git";
20

21
  /**
22
   * Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of a magic file.
23
   *
24
   * @param repoUrl the git remote URL to clone from.
25
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
26
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
27
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
28
   * @throws CliOfflineException if offline and cloning is needed.
29
   */
30
  void pullOrCloneIfNeeded(String repoUrl, String branch, Path targetRepository);
31

32
  /**
33
   * Checks if a git fetch is needed and performs it if required.
34
   * <p>
35
   * This method checks the last modified time of the `FETCH_HEAD` file in the `.git` directory to determine if a fetch is needed based on a predefined
36
   * threshold. If updates are available in the remote repository, it logs an information message prompting the user to pull the latest changes.
37
   *
38
   * @param targetRepository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
39
   * @return {@code true} if updates were detected after fetching from the remote repository, indicating that the local repository is behind the remote. *
40
   *     {@code false} if no updates were detected or if no fetching was performed (e.g., the cache threshold was not met or the context is offline)
41
   */
42
  boolean fetchIfNeeded(Path targetRepository);
43

44
  /**
45
   * Checks if a git fetch is needed and performs it if required.
46
   * <p>
47
   * This method checks the last modified time of the `FETCH_HEAD` file in the `.git` directory to determine if a fetch is needed based on a predefined
48
   * threshold. If updates are available in the remote repository, it logs an information message prompting the user to pull the latest changes.
49
   *
50
   * @param targetRepository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
51
   * @param remoteName the name of the remote repository, e.g., "origin".
52
   * @param branch the name of the branch to check for updates.
53
   * @return {@code true} if updates were detected after fetching from the remote repository, indicating that the local repository is behind the remote.
54
   *     {@code false} if no updates were detected or if no fetching was performed (e.g., the cache threshold was not met or the context is offline)
55
   */
56
  boolean fetchIfNeeded(Path targetRepository, String remoteName, String branch);
57

58
  /**
59
   * Checks if there are updates available for the Git repository in the specified target folder by comparing the local commit hash with the remote commit
60
   * hash.
61
   *
62
   * @param targetRepository the {@link Path} to the target folder where the git repository is located. This should be the folder containing the ".git"
63
   *     subfolder.
64
   * @return {@code true} if the remote repository contains commits that are not present in the local repository, indicating that updates are available.
65
   *     {@code false} if the local and remote repositories are in sync, or if there was an issue retrieving the commit hashes.
66
   */
67
  boolean isRepositoryUpdateAvailable(Path targetRepository);
68

69
  /**
70
   * Attempts a git pull and reset if required.
71
   *
72
   * @param repoUrl the git remote URL to clone from.
73
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
74
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
75
   * @throws CliOfflineException if offline and cloning is needed.
76
   */
77
  default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository) {
78

79
    pullOrCloneAndResetIfNeeded(repoUrl, targetRepository, null);
×
80
  }
×
81

82
  /**
83
   * Attempts a git pull and reset if required.
84
   *
85
   * @param repoUrl the git remote URL to clone from.
86
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
87
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
88
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
89
   * @throws CliOfflineException if offline and cloning is needed.
90
   */
91
  default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository, String branch) {
92

93
    pullOrCloneAndResetIfNeeded(repoUrl, targetRepository, branch, null);
×
94
  }
×
95

96
  /**
97
   * Attempts a git pull and reset if required.
98
   *
99
   * @param repoUrl the git remote URL to clone from.
100
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
101
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
102
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
103
   * @param remoteName the remote name e.g. origin.
104
   * @throws CliOfflineException if offline and cloning is needed.
105
   */
106
  void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository, String branch, String remoteName);
107

108
  /**
109
   * Runs a git pull or a git clone.
110
   *
111
   * @param gitRepoUrl the git remote URL to clone from.
112
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
113
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
114
   * @throws CliOfflineException if offline and cloning is needed.
115
   */
116
  void pullOrClone(String gitRepoUrl, Path targetRepository);
117

118
  /**
119
   * Runs a git pull or a git clone.
120
   *
121
   * @param gitRepoUrl the git remote URL to clone from.
122
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
123
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
124
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
125
   * @throws CliOfflineException if offline and cloning is needed.
126
   */
127
  void pullOrClone(String gitRepoUrl, Path targetRepository, String branch);
128

129
  /**
130
   * Runs a git clone.
131
   *
132
   * @param gitRepoUrl the {@link GitUrl} to use for the repository URL.
133
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
134
   *     git will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
135
   * @throws CliOfflineException if offline and cloning is needed.
136
   */
137
  void clone(GitUrl gitRepoUrl, Path targetRepository);
138

139
  /**
140
   * Runs a git pull.
141
   *
142
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
143
   *     git will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
144
   */
145
  void pull(Path targetRepository);
146

147
  /**
148
   * Runs a git diff-index to detect local changes and if so reverts them via git reset.
149
   *
150
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
151
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
152
   */
153
  default void reset(Path targetRepository) {
154

155
    reset(targetRepository, null);
×
156
  }
×
157

158
  /**
159
   * Runs a git diff-index to detect local changes and if so reverts them via git reset.
160
   *
161
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
162
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
163
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
164
   */
165
  default void reset(Path targetRepository, String branch) {
166

167
    reset(targetRepository, branch, null);
×
168
  }
×
169

170
  /**
171
   * Runs a git fetch.
172
   *
173
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
174
   *     git will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
175
   * @param remote the name of the remote repository, e.g., "origin". If {@code null} or empty, the default remote name "origin" will be used.
176
   * @param branch the name of the branch to check for updates.
177
   */
178
  void fetch(Path targetRepository, String remote, String branch);
179

180
  /**
181
   * Runs a git reset reverting all local changes to the git repository.
182
   *
183
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
184
   *     git will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
185
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
186
   * @param remoteName the name of the git remote e.g. "origin".
187
   */
188
  void reset(Path targetRepository, String branch, String remoteName);
189

190
  /**
191
   * Runs a git cleanup if untracked files were found.
192
   *
193
   * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where
194
   *     git will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
195
   */
196
  void cleanup(Path targetRepository);
197

198
  /**
199
   * Returns the URL of a git repository
200
   *
201
   * @param repository the {@link Path} to the folder where the git repository is located.
202
   * @return the url of the repository as a {@link String}.
203
   */
204
  String retrieveGitUrl(Path repository);
205

206
  /**
207
   * @param repository the {@link Path} to the folder where the git repository is located.
208
   * @return the name of the current branch.
209
   */
210
  String determineCurrentBranch(Path repository);
211

212
  /**
213
   * @param repository the {@link Path} to the folder where the git repository is located.
214
   * @return the name of the default origin.
215
   */
216
  String determineRemote(Path repository);
217

218
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc