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

devonfw / IDEasy / 13063267543

30 Jan 2025 11:34PM UTC coverage: 68.379% (-0.2%) from 68.557%
13063267543

push

github

web-flow
#954: improve repository support (#990)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

2857 of 4597 branches covered (62.15%)

Branch coverage included in aggregate %.

7391 of 10390 relevant lines covered (71.14%)

3.1 hits per line

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

66.67
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. For URLs like "https://github.com/devonfw/ide-urls.git" returns "ide-urls"
48
   *
49
   * @return the project name without ".git" extension
50
   */
51
  public String getProjectName() {
52

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

66
  /**
67
   * @param gitUrl the {@link #toString() string representation} of a {@link GitUrl}. May contain a branch name as {@code «url»#«branch»}.
68
   * @return the parsed {@link GitUrl}.
69
   */
70
  public static GitUrl of(String gitUrl) {
71

72
    int hashIndex = gitUrl.indexOf('#');
4✔
73
    String url = gitUrl;
2✔
74
    String branch = null;
2✔
75
    if (hashIndex > 0) {
2✔
76
      url = gitUrl.substring(0, hashIndex);
5✔
77
      branch = gitUrl.substring(hashIndex + 1);
6✔
78
    }
79
    return new GitUrl(url, branch);
6✔
80
  }
81

82
  /**
83
   * @param gitUrl the git {@link #url() URL}.
84
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MAIN}.
85
   */
86
  public static GitUrl ofMain(String gitUrl) {
87

88
    return new GitUrl(gitUrl, BRANCH_MAIN);
6✔
89
  }
90

91
  /**
92
   * @param gitUrl the git {@link #url() URL}.
93
   * @return a new instance of {@link GitUrl} with the given URL and {@link #BRANCH_MASTER}.
94
   */
95
  public static GitUrl ofMaster(String gitUrl) {
96

97
    return new GitUrl(gitUrl, BRANCH_MASTER);
×
98
  }
99
}
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