diff options
Diffstat (limited to 'src/git.rs')
-rw-r--r-- | src/git.rs | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -69,9 +69,14 @@ pub fn init( repo_name: &str, group: &Option<String>, description: &Option<String>, + branch: &str, ) -> Result<GitInitResult, ShackleError> { let mut init_opts = RepositoryInitOptions::new(); - init_opts.bare(true).mkdir(true).no_reinit(true); + init_opts + .bare(true) + .mkdir(true) + .no_reinit(true) + .initial_head(branch); let path = match group { Some(group) => { @@ -167,6 +172,24 @@ pub fn set_description(directory: &PathBuf, description: &str) -> Result<(), Sha } } +pub fn set_branch(directory: &PathBuf, branch: &str) -> Result<(), ShackleError> { + if !is_valid_git_repo_path(&directory)? { + return Err(ShackleError::InvalidDirectory); + } + + if let Ok(repo) = Repository::open_bare(&directory) { + repo.reference_symbolic( + "HEAD", + &format!("refs/heads/{branch}"), + true, + "shackle set-branch", + )?; + Ok(()) + } else { + Err(ShackleError::InvalidDirectory) + } +} + pub fn upload_pack(upload_pack_args: &GitUploadPackArgs) -> Result<(), ShackleError> { if !is_valid_git_repo_path(&upload_pack_args.directory)? { return Err(ShackleError::InvalidDirectory); |