def non_git_rebase(upstream_branch, directory=None): # Create a temporary storage directory tmp_dir = mkdtemp() # Get the root of the git repository git_root = get_root(directory) try: # Copy the new upstream source into the temporary directory with inbranch(upstream_branch): ignores = (".git", ".gitignore", ".svn", ".hgignore", ".hg", "CVS") parent_source = os.path.join(tmp_dir, "parent_source") my_copytree(git_root, parent_source, ignores) # Clear out the local branch execute_command("git rm -rf *", cwd=directory) # Collect .* files (excluding .git) dot_items = [] for item in os.listdir(git_root): if item in [".git", "..", "."]: continue if item.startswith("."): dot_items.append(item) # Remove and .* files missed by 'git rm -rf *' if len(dot_items) > 0: execute_command("git rm -rf " + " ".join(dot_items), cwd=directory) # Clear out any untracked files execute_command("git clean -fdx", cwd=directory) # for good measure? # Copy the parent source into the newly cleaned directory my_copytree(parent_source, git_root) # Commit changes to the repository execute_command("git add ./*", cwd=directory) # Collect .* files dot_items = [] for item in os.listdir(git_root): if item in [".git", "..", "."]: continue if item.startswith("."): dot_items.append(item) # Add any .* files missed by 'git add ./*' if len(dot_items) > 0: execute_command("git add " + " ".join(dot_items), cwd=directory) # Remove any straggling untracked files execute_command("git clean -dXf", cwd=directory) # Only if we have local changes commit # (not true if the upstream didn't change any files) cmd = "git commit " if not has_changes(directory): cmd += "--allow-empty " cmd += "-m \"Rebase from '" + upstream_branch + "'" if not has_changes(directory): cmd += " (no changes)" cmd += '"' execute_command(cmd, cwd=directory) finally: # Clean up if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def non_git_rebase(upstream_branch, directory=None): # Create a temporary storage directory tmp_dir = mkdtemp() # Get the root of the git repository git_root = get_root(directory) try: # Copy the new upstream source into the temporary directory with inbranch(upstream_branch): ignores = ('.git', '.gitignore', '.svn', '.hgignore', '.hg', 'CVS') parent_source = os.path.join(tmp_dir, 'parent_source') my_copytree(git_root, parent_source, ignores) # Clear out the local branch execute_command('git rm -rf *', cwd=directory) # Collect .* files (excluding .git) dot_items = [] for item in os.listdir(git_root): if item in ['.git', '..', '.']: continue if item.startswith('.'): dot_items.append(item) # Remove and .* files missed by 'git rm -rf *' if len(dot_items) > 0: execute_command('git rm -rf ' + ' '.join(dot_items), cwd=directory) # Clear out any untracked files execute_command('git clean -fdx', cwd=directory) # for good measure? # Copy the parent source into the newly cleaned directory my_copytree(parent_source, git_root) # Commit changes to the repository execute_command('git add ./*', cwd=directory) # Collect .* files dot_items = [] for item in os.listdir(git_root): if item in ['.git', '..', '.']: continue if item.startswith('.'): dot_items.append(item) # Add any .* files missed by 'git add ./*' if len(dot_items) > 0: execute_command('git add ' + ' '.join(dot_items), cwd=directory) # Remove any straggling untracked files execute_command('git clean -dXf', cwd=directory) # Only if we have local changes commit # (not true if the upstream didn't change any files) cmd = 'git commit ' if not has_changes(directory): cmd += '--allow-empty ' cmd += '-m "Rebase from \'' + upstream_branch + "'" if not has_changes(directory): cmd += " (no changes)" cmd += '"' execute_command(cmd, cwd=directory) finally: # Clean up if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def upconvert_bloom_to_config_branch(): global _has_checked_bloom_branch if _has_checked_bloom_branch: return # Assert that this repository does not have multiple remotes check_for_multiple_remotes() if get_root() is None: # Not a git repository return track_branches(['bloom', BLOOM_CONFIG_BRANCH]) if show('bloom', PLACEHOLDER_FILE) is not None: return if show('bloom', 'bloom.conf') is not None: # Wait for the bloom.conf upconvert... return if not branch_exists('bloom'): return _has_checked_bloom_branch = True info("Moving configurations from deprecated 'bloom' branch " "to the '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) tmp_dir = mkdtemp() git_root = get_root() try: # Copy the new upstream source into the temporary directory with inbranch('bloom'): ignores = ('.git', '.gitignore', '.svn', '.hgignore', '.hg', 'CVS') configs = os.path.join(tmp_dir, 'configs') my_copytree(git_root, configs, ignores) if [x for x in os.listdir(os.getcwd()) if x not in ignores]: execute_command('git rm -rf ./*') with open(PLACEHOLDER_FILE, 'w') as f: f.write("""\ This branch ('bloom') has been deprecated in favor of storing settings and overlay files in the master branch. Please goto the master branch for anything which referenced the bloom branch. You can delete this branch at your convenience. """) execute_command('git add ' + PLACEHOLDER_FILE) if has_changes(): execute_command('git commit -m "DEPRECATING BRANCH"') if not branch_exists(BLOOM_CONFIG_BRANCH): info("Creating '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) create_branch(BLOOM_CONFIG_BRANCH, orphaned=True) with inbranch(BLOOM_CONFIG_BRANCH): my_copytree(configs, git_root) execute_command('git add ./*') if has_changes(): execute_command('git commit -m ' '"Moving configs from bloom branch"') finally: # Clean up if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def non_git_rebase(upstream_branch, directory=None): # Create a temporary storage directory tmp_dir = mkdtemp() # Get the root of the git repository git_root = get_root(directory) try: # Copy the new upstream source into the temporary directory with inbranch(upstream_branch): ignores = ('.git', '.gitignore', '.svn', '.hgignore', '.hg', 'CVS') parent_source = os.path.join(tmp_dir, 'parent_source') my_copytree(git_root, parent_source, ignores) # Clear out any untracked files execute_command('git clean -fdx', cwd=directory) # for good measure? # Collect files (excluding .git) items = [] for item in os.listdir(git_root): if item in ['.git', '..', '.']: continue items.append(item) # Remove all files if len(items) > 0: execute_command('git rm -rf ' + ' '.join(items), cwd=directory) # Copy the parent source into the newly cleaned directory my_copytree(parent_source, git_root) # Commit changes to the repository execute_command('git add ./*', cwd=directory) # Collect .* files dot_items = [] for item in os.listdir(git_root): if item in ['.git', '..', '.']: continue if item.startswith('.'): dot_items.append(item) # Add any .* files missed by 'git add ./*' if len(dot_items) > 0: execute_command('git add ' + ' '.join(dot_items), cwd=directory) # Remove any straggling untracked files execute_command('git clean -dXf', cwd=directory) # Only if we have local changes commit # (not true if the upstream didn't change any files) cmd = 'git commit ' if not has_changes(directory): cmd += '--allow-empty ' cmd += '-m "Rebase from \'' + upstream_branch + "'" if not has_changes(directory): cmd += " (no changes)" cmd += '"' execute_command(cmd, cwd=directory) finally: # Clean up if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)