From 48b786e6d8fa443c8e3065cac574ab2cda51edd7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Thu, 27 Aug 2020 10:20:04 -0600 Subject: [PATCH] Update to origin when fetching --- src/bin/cook.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/bin/cook.rs b/src/bin/cook.rs index 9f0c3f214..173a3f808 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -209,16 +209,23 @@ fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> { run_command(command)?; } else { //TODO: complicated stuff to check and reset branch to origin - // ORIGIN_BRANCH="$(git branch --remotes | grep '^ origin/HEAD -> ' | cut -d ' ' -f 5-)" - // if [ -n "$BRANCH" ] - // then - // ORIGIN_BRANCH="origin/$BRANCH" - // fi - // - // if [ "$(git rev-parse HEAD)" != "$(git rev-parse $ORIGIN_BRANCH)" ] - // then - // git checkout -B "$(echo "$ORIGIN_BRANCH" | cut -d / -f 2-)" "$ORIGIN_BRANCH" - // fi + let mut command = Command::new("bash"); + command.arg("-c").arg(r#" +ORIGIN_BRANCH="$(git branch --remotes | grep '^ origin/HEAD -> ' | cut -d ' ' -f 5-)" +if [ -n "$BRANCH" ] +then + ORIGIN_BRANCH="origin/$BRANCH" +fi + +if [ "$(git rev-parse HEAD)" != "$(git rev-parse $ORIGIN_BRANCH)" ] +then + git checkout -B "$(echo "$ORIGIN_BRANCH" | cut -d / -f 2-)" "$ORIGIN_BRANCH" +fi"#); + if let Some(branch) = branch { + command.env("BRANCH", branch); + } + command.current_dir(&source_dir); + run_command(command)?; } // Sync submodules URL -- GitLab