Skip to content

Commit 6af999e

Browse files
Adding branch & full history options for git dependency source
1 parent 6ca5449 commit 6af999e

File tree

8 files changed

+118
-14
lines changed

8 files changed

+118
-14
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ Dependencies:
149149
Git:
150150
# Git repository URL
151151
URL: "https://github.com/MyUser/MyLibrary.git"
152+
153+
# (Optional) Branch name or tag name. Full ref path is accepted as well.
154+
# Defaults to default branch on specified git repo if this is not specified
155+
# Branch: "MyBranch"
156+
157+
# (Optional) Checkout full git history or just the target commit. Defaults to false
158+
# FullHistory: false
152159

153160
# Dependency or import YAML file exists in local filesystem directory,
154161
# and needs to be copied to build directory

Include/runcpp2/Data/GitSource.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace runcpp2
1212
{
1313
public:
1414
std::string URL;
15+
std::string Branch;
16+
bool FullHistory = false;
1517

1618
bool ParseYAML_Node(ryml::ConstNodeRef& node);
1719
std::string ToString(std::string indentation) const;
@@ -20,4 +22,4 @@ namespace runcpp2
2022
}
2123
}
2224

23-
#endif
25+
#endif

Src/Tests/Data/DependencySourceTest.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int main(int argc, char** argv)
1717
const char* yamlStr = R"(
1818
Git:
1919
URL: https://github.com/user/repo.git
20+
Branch: master
21+
FullHistory: true
2022
)";
2123

2224
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
@@ -37,7 +39,9 @@ int main(int argc, char** argv)
3739
const runcpp2::Data::GitSource* git =
3840
mpark::get_if<runcpp2::Data::GitSource>(&dependencySource.Source);
3941
ssTEST_OUTPUT_ASSERT("Should be Git source", git != nullptr);
40-
ssTEST_OUTPUT_ASSERT("URL", git->URL == "https://github.com/user/repo.git");
42+
ssTEST_OUTPUT_ASSERT("URL", git->URL, "https://github.com/user/repo.git");
43+
ssTEST_OUTPUT_ASSERT("Branch", git->Branch, "master");
44+
ssTEST_OUTPUT_ASSERT("FullHistory", git->FullHistory, true);
4145

4246
//Test ToString() and Equals()
4347
ssTEST_OUTPUT_EXECUTION
@@ -184,9 +188,34 @@ int main(int argc, char** argv)
184188
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
185189
);
186190

187-
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", !parseResult);
191+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
188192
};
189-
193+
194+
ssTEST("DependencySource Should Handle Invalid FullHistory Option")
195+
{
196+
ssTEST_OUTPUT_SETUP
197+
(
198+
const char* yamlStr = R"(
199+
Git:
200+
URL: https://github.com/user/repo.git
201+
FullHistory: What
202+
)";
203+
204+
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
205+
ryml::ConstNodeRef root = tree.rootref();
206+
207+
runcpp2::Data::DependencySource dependencySource;
208+
);
209+
210+
ssTEST_OUTPUT_EXECUTION
211+
(
212+
ryml::ConstNodeRef nodeRef = root;
213+
bool parseResult = dependencySource.ParseYAML_Node(nodeRef);
214+
);
215+
216+
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should fail", parseResult, false);
217+
};
218+
190219
ssTEST_END_TEST_GROUP();
191220
return 0;
192221
}

Src/runcpp2/Data/GitSource.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
99

1010
std::vector<NodeRequirement> requirements =
1111
{
12-
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false)
12+
NodeRequirement("URL", ryml::NodeType_e::KEYVAL, true, false),
13+
NodeRequirement("Branch", ryml::NodeType_e::KEYVAL, false, false),
14+
NodeRequirement("FullHistory", ryml::NodeType_e::KEYVAL, false, false)
1315
};
1416

1517
if(!CheckNodeRequirements(node, requirements))
@@ -19,6 +21,12 @@ bool runcpp2::Data::GitSource::ParseYAML_Node(ryml::ConstNodeRef& node)
1921
}
2022

2123
node["URL"] >> URL;
24+
if(ExistAndHasChild(node, "Branch"))
25+
node["Branch"] >> Branch;
26+
27+
if(ExistAndHasChild(node, "FullHistory"))
28+
node["FullHistory"] >> FullHistory;
29+
2230
return true;
2331

2432
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
@@ -29,10 +37,13 @@ std::string runcpp2::Data::GitSource::ToString(std::string indentation) const
2937
std::string out;
3038
out += indentation + "Git:\n";
3139
out += indentation + " URL: " + GetEscapedYAMLString(URL) + "\n";
40+
if(!Branch.empty())
41+
out += indentation + " Branch: " + GetEscapedYAMLString(Branch) + "\n";
42+
out += indentation + " FullHistory: " + (FullHistory ? "true" : "false") + "\n";
3243
return out;
3344
}
3445

3546
bool runcpp2::Data::GitSource::Equals(const GitSource& other) const
3647
{
37-
return URL == other.URL;
38-
}
48+
return URL == other.URL && Branch == other.Branch && FullHistory == other.FullHistory;
49+
}

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ namespace
115115
const runcpp2::Data::GitSource* git =
116116
mpark::get_if<runcpp2::Data::GitSource>(&(dependency.Source.Source));
117117

118-
std::string gitCloneCommand = "git clone " + git->URL;
118+
std::string gitCloneCommand =
119+
std::string("git clone ") +
120+
(git->FullHistory ? "" : "--depth 1 ") +
121+
(
122+
git->Branch.empty() ?
123+
std::string("") :
124+
std::string("--branch ") + git->Branch
125+
) +
126+
git->URL;
119127

120128
ssLOG_INFO("Running git clone command: " << gitCloneCommand << " in " <<
121129
buildDir.string());

mkdocs/docs/TODO.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Roadmap
22

3-
## Planned
3+
## Done
4+
5+
!!! info "`latest` version"
6+
- Async/Multi-thread compile and dependencies processing
7+
- More git options
8+
- Add branch/tag option for git
9+
- Add initialize submodule option for git
10+
411

12+
## Planned
513
- Ability to skip DefaultPlatform and DefaultProfile
6-
- More git options
7-
- Add branch/tag option for git
8-
- Add initialize submodule option for git
914
- Allow runcpp2 to be library for scriptable pipeline
1015
- Smoother CMake support by reading cmake target properties (https://stackoverflow.com/a/56738858/23479578)
1116
- Add the ability for user to specify custom substitution options which applies to all fields
@@ -37,6 +42,4 @@
3742
- Allow Languages to override FileExtensions in compiler profile (?)
3843
- Custom Platform
3944
- Ability to specify custom run commands
40-
-
41-
4245

mkdocs/docs/build_settings.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@
312312
- Optional: `false`
313313
- Default: None
314314
- Description: The url of the git repository.
315+
- `Branch`
316+
- Type: `string`
317+
- Optional: `true`
318+
- Default: None
319+
- Description: Branch name or tag name. Full ref path is accepted as well.
320+
- !!! info "This requires `latest` version"
321+
- `FullHistory`
322+
- Type: `bool`
323+
- Optional: `true`
324+
- Default: `false`
325+
- Description: Checkout full git history or just the target commit.
326+
- !!! info "This requires `latest` version"
315327
- `Local`
316328
- Type: `map` with child fields
317329
- Optional: `true` if `ImportPath` is specified or `Git` is specified
@@ -547,6 +559,13 @@ Dependencies:
547559
Git:
548560
# Git repository URL
549561
URL: "https://github.com/MyUser/MyLibrary.git"
562+
563+
# (Optional) Branch name or tag name. Full ref path is accepted as well.
564+
# Defaults to default branch on specified git repo if this is not specified
565+
# Branch: "MyBranch"
566+
567+
# (Optional) Checkout full git history or just the target commit. Defaults to false
568+
# FullHistory: false
550569

551570
# Dependency or import YAML file exists in local filesystem directory,
552571
# and needs to be copied to build directory

mkdocs/docs/guides/external_dependencies.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This is configured under the `Source` section. We currently support 2 sources:
3535
Source:
3636
Git:
3737
URL: "https://github.com/MyUser/MyLibrary.git"
38+
3839
LibraryType: Static
3940
IncludePaths:
4041
- "include/MyLibrary"
@@ -56,6 +57,30 @@ This is configured under the `Source` section. We currently support 2 sources:
5657

5758
---
5859

60+
## Specifying Git Clone Options
61+
62+
!!! info "This requires `latest` version"
63+
64+
You can specify the target branch/tag name and to clone whole git history or not with:
65+
`Branch` and `FullHistory`.
66+
67+
A normal clone without full history will be performed if none of these are specified.
68+
69+
???+ example
70+
```yaml
71+
Dependencies:
72+
...
73+
Source:
74+
Git:
75+
URL: "https://github.com/MyUser/MyLibrary.git"
76+
Branch: "SpecialBranch"
77+
FullHistory: true
78+
...
79+
```
80+
81+
82+
---
83+
5984
## Adding Include Paths And Link Settings
6085

6186
### Include Paths

0 commit comments

Comments
 (0)