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

devonfw / IDEasy / 12356873353

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

Pull #850

github

web-flow
Merge 532436561 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

75.0
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 {
8✔
21
    if (url.contains("#")) {
4✔
22
      String message = "Invalid git URL " + url;
3✔
23
      assert false : message;
6✔
24
    }
25
  }
1✔
26

27
  /**
28
   * Converts the Git URL based on the specified {@link GitUrlSyntax}.
29
   *
30
   * @param syntax the preferred {@link GitUrlSyntax} (SSH or HTTPS).
31
   * @return the converted {@link GitUrl} or the original if no conversion is required.
32
   */
33
  public GitUrl convert(GitUrlSyntax syntax) {
34
    return syntax.format(this);
4✔
35
  }
36

37
  @Override
38
  public String toString() {
39

40
    if (this.branch == null) {
3✔
41
      return this.url;
3✔
42
    }
43
    return this.url + "#" + this.branch;
6✔
44
  }
45

46
  /**
47
   * Extracts the project name from an git URL.
48
   * For URLs like "https://github.com/devonfw/ide-urls.git" returns "ide-urls"
49
   *
50
   * @return the project name without ".git" extension
51
   */
52
  public String getProjectName() {
53
    String path = this.url.substring(this.url.indexOf("://") + 3);
×
54
    if (path.endsWith(".git")) {
×
55
      path = path.substring(0, path.length() - 4);
×
56
    }
57
    String[] parts = path.split("/");
×
58
    return parts[parts.length - 1];
×
59
  }
60

61
  /**
62
   * @param gitUrl the {@link #toString() string representation} of a {@link GitUrl}. May contain a branch name as {@code «url»#«branch»}.
63
   * @return the parsed {@link GitUrl}.
64
   */
65
  public static GitUrl of(String gitUrl) {
66

67
    int hashIndex = gitUrl.indexOf('#');
4✔
68
    String url = gitUrl;
2✔
69
    String branch = null;
2✔
70
    if (hashIndex > 0) {
2✔
71
      url = gitUrl.substring(0, hashIndex);
5✔
72
      branch = gitUrl.substring(hashIndex + 1);
6✔
73
    }
74
    return new GitUrl(url, branch);
6✔
75
  }
76

77
  /**
78
   * @param gitUrl the git {@link #url() URL}.
79
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MAIN}.
80
   */
81
  public static GitUrl ofMain(String gitUrl) {
82

83
    return new GitUrl(gitUrl, BRANCH_MAIN);
6✔
84
  }
85

86
  /**
87
   * @param gitUrl the git {@link #url() URL}.
88
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MASTER}.
89
   */
90
  public static GitUrl ofMaster(String gitUrl) {
91

92
    return new GitUrl(gitUrl, BRANCH_MASTER);
×
93
  }
94
}
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