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

devonfw / IDEasy / 12357095455

16 Dec 2024 04:35PM UTC coverage: 67.215% (-0.2%) from 67.459%
12357095455

Pull #850

github

web-flow
Merge e465baecc into 52afdd7c7
Pull Request #850: #757: Settings in code repository

2574 of 4176 branches covered (61.64%)

Branch coverage included in aggregate %.

6668 of 9574 relevant lines covered (69.65%)

3.06 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/git/GitContext.java
1
package com.devonfw.tools.ide.git;
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 gitUrl the {@link GitUrl} to clone from.
25
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
26
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
27
   * @throws CliOfflineException if offline and cloning is needed.
28
   */
29
  void pullOrCloneIfNeeded(GitUrl gitUrl, Path repository);
30

31
  /**
32
   * Checks if a git fetch is needed and performs it if required.
33
   * <p>
34
   * 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
35
   * threshold. If updates are available in the remote repository, it logs an information message prompting the user to pull the latest changes.
36
   *
37
   * @param repository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
38
   * @return {@code true} if updates were detected after fetching from the remote repository, indicating that the local repository is behind the remote. *
39
   *     {@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)
40
   */
41
  boolean fetchIfNeeded(Path repository);
42

43
  /**
44
   * Checks if a git fetch is needed and performs it if required.
45
   * <p>
46
   * 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
47
   * threshold. If updates are available in the remote repository, it logs an information message prompting the user to pull the latest changes.
48
   *
49
   * @param repository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
50
   * @param remoteName the name of the remote repository, e.g., "origin".
51
   * @param branch the name of the branch to check for updates.
52
   * @return {@code true} if updates were detected after fetching from the remote repository, indicating that the local repository is behind the remote.
53
   *     {@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)
54
   */
55
  boolean fetchIfNeeded(Path repository, String remoteName, String branch);
56

57
  /**
58
   * 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
59
   * hash.
60
   *
61
   * @param repository the {@link Path} to the target folder where the git repository is located.
62
   * @return {@code true} if the remote repository contains commits that are not present in the local repository, indicating that updates are available.
63
   *     {@code false} if the local and remote repositories are in sync, or if there was an issue retrieving the commit hashes.
64
   */
65
  boolean isRepositoryUpdateAvailable(Path repository);
66

67
  /**
68
   * 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
69
   * hash.
70
   *
71
   * @param repository the {@link Path} to the target folder where the git repository is located.
72
   * @param trackedCommitIdPath the {@link Path} to a file containing the last tracked commit ID of this repository.
73
   * @return {@code true} if the remote repository contains commits that are not present in the local repository, indicating that updates are available.
74
   *     {@code false} if the local and remote repositories are in sync, or if there was an issue retrieving the commit hashes.
75
   */
76
  boolean isRepositoryUpdateAvailable(Path repository, Path trackedCommitIdPath);
77

78
  /**
79
   * Attempts a git pull and reset if required.
80
   *
81
   * @param gitUrl the {@link GitUrl} to clone from.
82
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
83
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
84
   * @param remoteName the remote name e.g. origin.
85
   * @throws CliOfflineException if offline and cloning is needed.
86
   */
87
  void pullOrCloneAndResetIfNeeded(GitUrl gitUrl, Path repository, String remoteName);
88

89
  /**
90
   * Runs a git pull or a git clone.
91
   *
92
   * @param gitUrl the {@link GitUrl} to clone from.
93
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
94
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
95
   * @throws CliOfflineException if offline and cloning is needed.
96
   */
97
  void pullOrClone(GitUrl gitUrl, Path repository);
98

99
  /**
100
   * Runs a git clone.
101
   *
102
   * @param gitUrl the {@link GitUrl} to use for the repository URL.
103
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
104
   *     will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
105
   * @throws CliOfflineException if offline and cloning is needed.
106
   */
107
  void clone(GitUrl gitUrl, Path repository);
108

109
  /**
110
   * Runs a git pull.
111
   *
112
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
113
   *     will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
114
   */
115
  void pull(Path repository);
116

117
  /**
118
   * Runs a git diff-index to detect local changes and if so reverts them via git reset.
119
   *
120
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
121
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
122
   */
123
  default void reset(Path repository) {
124

125
    reset(repository, null);
×
126
  }
×
127

128
  /**
129
   * Runs a git diff-index to detect local changes and if so reverts them via git reset.
130
   *
131
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
132
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
133
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
134
   */
135
  default void reset(Path repository, String branch) {
136

137
    reset(repository, branch, null);
×
138
  }
×
139

140
  /**
141
   * Runs a git fetch.
142
   *
143
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
144
   *     will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
145
   * @param remote the name of the remote repository, e.g., "origin". If {@code null} or empty, the default remote name "origin" will be used.
146
   * @param branch the name of the branch to check for updates.
147
   */
148
  void fetch(Path repository, String remote, String branch);
149

150
  /**
151
   * Runs a git reset reverting all local changes to the git repository.
152
   *
153
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
154
   *     will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
155
   * @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
156
   * @param remoteName the name of the git remote e.g. "origin".
157
   */
158
  void reset(Path repository, String branch, String remoteName);
159

160
  /**
161
   * Runs a git cleanup if untracked files were found.
162
   *
163
   * @param repository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
164
   *     will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
165
   */
166
  void cleanup(Path repository);
167

168
  /**
169
   * Returns the URL of a git repository
170
   *
171
   * @param repository the {@link Path} to the folder where the git repository is located.
172
   * @return the url of the repository as a {@link String}.
173
   */
174
  String retrieveGitUrl(Path repository);
175

176
  /**
177
   * @param repository the {@link Path} to the folder where the git repository is located.
178
   * @return the name of the current branch.
179
   */
180
  String determineCurrentBranch(Path repository);
181

182
  /**
183
   * @param repository the {@link Path} to the folder where the git repository is located.
184
   * @return the name of the default origin.
185
   */
186
  String determineRemote(Path repository);
187

188
  /**
189
   * Saves the current git commit ID of a repository to a file given as an argument.
190
   *
191
   * @param repository the path to the git repository
192
   * @param trackedCommitIdPath the path to the file where the commit Id will be written.
193
   */
194
  void saveCurrentCommitId(Path repository, Path trackedCommitIdPath);
195
}
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

© 2025 Coveralls, Inc