-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Submodule Versioning #23
Conversation
Thanks! It could certainly be interesting to support information for submodules too. But I think the macro should expand to an array of submodule entries, giving the path and version information of each. Now it just expands to one string literal? |
@de-vri-es This is ready for re-review. |
Output looks good. The only thing I'm contemplating is if we should use a different type for the submodule entries. A tuple seems more logical than a (Didn't look at the implementation yet.) |
for line in newline_split { | ||
let line = line.to_string(); | ||
let line_split: Vec<&str> = line.split(':').collect(); | ||
assert!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proc macro should never panic. This should be a compile error instead. But I also think the check should probably be removed. If people use colons in their tags, it should still just work.
But maybe we shouldn't use git submodule foreach
, but just get a list of submodules and do the foreach
ourselves. Then we avoid the need to parse output at all (what if the submodule path also has a colon?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, and removed foreach args. Also renamed describe_args
back to args
to be more inline with the git_version
macro.
@de-vri-es I think I want to avoid using custom structs because I personally like using the I think an output of |
It wouldn't be a technical problem, but I agree, it's nice to limit the number of types/functions you need. So fair, lets not go for a custom struct. I was also thinking maybe the submodule path should still be
Yeah, an array is good. If people want, they can easily turn it into a slice by taking a reference: const SUBMODULE_VERSIONS: &[(&str, &str)] = &git_version_modules!(); By expanding to an array, we do give people the option to use One more bikeshed point: I think |
.gitmodules
Outdated
@@ -0,0 +1,6 @@ | |||
[submodule "test-child-repo"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to set up a custom testing repo for this instead of adding submodules. But I will take care of this part, since I also think they should be in the same organization :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed submodules and added more effective test. Also fixed some issues that popped up when this macro is ran in a project with no submodules.
@de-vri-es Renamed the macro, also updated docs for usage. |
@de-vri-es ping |
let mut args: Vec<String> = "submodule foreach --quiet --recursive" | ||
.to_string() | ||
.split(' ') | ||
.map(|x| x.to_string()) | ||
.collect(); | ||
|
||
args.push("echo $displaypath".to_string()); | ||
|
||
let result = run_git("git submodule", Command::new("git").args(args))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut args: Vec<String> = "submodule foreach --quiet --recursive" | |
.to_string() | |
.split(' ') | |
.map(|x| x.to_string()) | |
.collect(); | |
args.push("echo $displaypath".to_string()); | |
let result = run_git("git submodule", Command::new("git").args(args))?; | |
let result = run_git( | |
"git submodule", | |
Command::new("git") | |
.arg("submodule") | |
.arg("foreach") | |
.arg("--quiet") | |
.arg("--recursive") | |
.arg("echo $displaypath"), | |
)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does echo $displaypath
work on windows though? Maybe we should parse the .gitmodules
file instead relying on git submodule foreach
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lemme check real quick.
Edit: Yep! It works. The shell that executes the command must be implemented by git. Tested on Powershell and Command Prompt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :)
|
||
})) | ||
} | ||
Err(_) if args.fallback.is_some() => Ok(quote!([("fallback", args.fallback)])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this makes sense here. For git_version!()
, the fallback means: if "git describe fails, give this as version instead".
I think the fallback should have the same meaning for submodules: each submodule entry should apply the fallback independently if git describe
fails.
At the very least, it will mean that the submodule paths are always real paths. With the current interpretation of the fallback argument, you can't distinguish between the fallback being used or a submodule at path "fallback".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it felt clunky. I will implement this tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@de-vri-es Fixed up to work as you described. Will conditionally add a fallback on a per-submodule basis if a fallback is provided, and throw a compiler error otherwise, just like git_version!()
.
Co-authored-by: Maarten de Vries <[email protected]>
Co-authored-by: Maarten de Vries <[email protected]>
Released as Thanks for the PR! |
Added new
git_version_modules
macro that uses a combination ofgit submodule foreach
andgit describe
to format a block of text that accomplishes whatgit_version
does for the root repository.Use
Given the file structure of this PR:
Example output: