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

devonfw / IDEasy / 21624876932

03 Feb 2026 09:35AM UTC coverage: 70.444% (-0.002%) from 70.446%
21624876932

Pull #1700

github

web-flow
Merge f91d4d4bb into 70a7fbf5d
Pull Request #1700: #1699 verify input git url

4044 of 6326 branches covered (63.93%)

Branch coverage included in aggregate %.

10490 of 14306 relevant lines covered (73.33%)

3.18 hits per line

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

87.93
cli/src/main/java/com/devonfw/tools/ide/git/GitUrl.java
1
package com.devonfw.tools.ide.git;
2

3
/**
4
 * Handles parsing of git URLs.
5
 *
6
 * @param url the git url e.g. https://github.com/devonfw/ide-urls.git.
7
 * @param branch the branch name e.g. master.
8
 */
9
public record GitUrl(String url, String branch) {
1✔
10

11
  /** {@link #branch() Branch} @{@value }. */
12
  public static final String BRANCH_MAIN = "main";
13

14
  /** {@link #branch() Branch} @{@value }. */
15
  public static final String BRANCH_MASTER = "master";
16

17
  /**
18
   * The constructor.
19
   */
20
  public GitUrl(String url, String branch) {
2✔
21
    this.url = url;
3✔
22
    this.branch = branch;
3✔
23
    if (url.contains("#")) {
4✔
24
      String message = "Invalid git URL " + url;
3✔
25
      assert false : message;
6✔
26
    }
27
    if (!isValid()) {
3✔
28
      String message = "Invalid git URL - has to start with https, http or ssh: " + url;
3✔
29
      assert false : message;
6✔
30
    }
31
  }
1✔
32

33
  /**
34
   * Converts the Git URL based on the specified {@link GitUrlSyntax}.
35
   *
36
   * @param syntax the preferred {@link GitUrlSyntax} (SSH or HTTPS).
37
   * @return the converted {@link GitUrl} or the original if no conversion is required.
38
   */
39
  public GitUrl convert(GitUrlSyntax syntax) {
40
    return syntax.format(this);
4✔
41
  }
42

43
  /**
44
   * Extracts the project name from an git URL. For URLs like "https://github.com/devonfw/ide-urls.git" returns "ide-urls"
45
   *
46
   * @return the project name without ".git" extension
47
   */
48
  public String getProjectName() {
49

50
    int lastSlash = this.url.lastIndexOf('/');
5✔
51
    String path;
52
    if (lastSlash >= 0) {
2!
53
      path = this.url.substring(lastSlash + 1);
8✔
54
    } else {
55
      path = this.url; // actually invalid URL
×
56
    }
57
    if (path.endsWith(".git")) {
4✔
58
      path = path.substring(0, path.length() - 4);
8✔
59
    }
60
    return path;
2✔
61
  }
62

63
  /**
64
   * Checks that the input URL starts with http://, https://, ssh:// or git@.
65
   *
66
   * @return true if the URL starts with http://, https://, ssh:// or git@ - otherwise returns false.
67
   */
68
  public boolean isValid() {
69
    if (url == null || url.isBlank()) {
7!
70
      return false;
×
71
    }
72
    return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ssh://") || url.startsWith("git@");
24!
73
  }
74

75
  @Override
76
  public String toString() {
77

78
    if (this.branch == null) {
3✔
79
      return this.url;
3✔
80
    }
81
    return this.url + "#" + this.branch;
6✔
82
  }
83

84
  /**
85
   * @param gitUrl the {@link #toString() string representation} of a {@link GitUrl}. May contain a branch name as {@code «url»#«branch»}.
86
   * @return the parsed {@link GitUrl}.
87
   */
88
  public static GitUrl of(String gitUrl) {
89

90
    int hashIndex = gitUrl.indexOf('#');
4✔
91
    String url = gitUrl;
2✔
92
    String branch = null;
2✔
93
    if (hashIndex > 0) {
2✔
94
      url = gitUrl.substring(0, hashIndex);
5✔
95
      branch = gitUrl.substring(hashIndex + 1);
6✔
96
    }
97
    return new GitUrl(url, branch);
6✔
98
  }
99

100
  /**
101
   * @param gitUrl the git {@link #url() URL}.
102
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MAIN}.
103
   */
104
  public static GitUrl ofMain(String gitUrl) {
105

106
    return new GitUrl(gitUrl, BRANCH_MAIN);
6✔
107
  }
108

109
  /**
110
   * @param gitUrl the git {@link #url() URL}.
111
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MASTER}.
112
   */
113
  public static GitUrl ofMaster(String gitUrl) {
114

115
    return new GitUrl(gitUrl, BRANCH_MASTER);
×
116
  }
117
}
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