Skip to content
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

Support cloning / git pulling from non-tagged commits #126

Open
kethinov opened this issue Sep 20, 2024 · 0 comments
Open

Support cloning / git pulling from non-tagged commits #126

kethinov opened this issue Sep 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kethinov
Copy link
Member

Right now if you you set -b to something that isn't a tagged commit, it will clone, but it will fail to re-validate when you re-run the postinstall script because it fails const output = spawnSync('git', ['describe', '--tags'], { ....

To resolve this, we need to recognize when -b is set to something that isn't a tagged commit and instead of doing the git describe, we do a git fetch, git status or git log instead to see if there are new commits, then do a git pull instead of checking to see if we need to re-clone.

e.g.

const { exec } = require('child_process');

function checkForNewCommits() {
  // Fetch the latest changes from the remote repository
  exec('git fetch', (fetchError, fetchStdout, fetchStderr) => {
    if (fetchError) {
      console.error(`Error fetching from remote: ${fetchError}`);
      return;
    }

    // Compare the local branch with the remote branch
    exec('git status -uno', (statusError, statusStdout, statusStderr) => {
      if (statusError) {
        console.error(`Error checking status: ${statusError}`);
        return;
      }

      // Check if there are new commits
      if (statusStdout.includes('Your branch is behind')) {
        console.log('There are new commits available.');
      } else {
        console.log('Your branch is up to date.');
      }
    });
  });
}

// Example usage
checkForNewCommits();

If this is successfully implemented, we could probably reuse the logic elsewhere as well to prevent re-cloning in situations where it is not necessary. For example, if you have -b 1.0.0 that is a tagged commit on main, then you update it to -b 1.0.1 which is a new tagged commit also on main, it would be nice if instead of re-cloning, it simply does a fetch and pull, but only pull the commits up to the new tag via git checkout tags/1.0.1 or whatever.

e.g.

const { exec } = require('child_process');

function pullUpToTag(tag) {
  // Fetch all tags from the remote repository
  exec('git fetch --tags', (fetchError, fetchStdout, fetchStderr) => {
    if (fetchError) {
      console.error(`Error fetching tags: ${fetchError}`);
      return;
    }

    // Checkout the specific tag
    exec(`git checkout tags/${tag}`, (checkoutError, checkoutStdout, checkoutStderr) => {
      if (checkoutError) {
        console.error(`Error checking out tag ${tag}: ${checkoutError}`);
        return;
      }

      console.log(`Successfully checked out tag ${tag}`);
    });
  });
}

// Example usage
pullUpToTag('1.0.1');
@kethinov kethinov added the enhancement New feature or request label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant