Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions freepbx_git.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
array('--setup', 'Setup new freepbx dev tools environment (use --force to re-setup environment)'),
array('--clean', 'Prunes all tags and branches that do no exist on the remote, can be used with the -m command for individual'),
array('--refresh', 'Updates all local modules with their remote changes (!!you will lose all untracked branches!!)'),
array('--force', 'With --refresh, force-update local tags on conflict without prompting (also used by --setup)'),
array('--refreshhard', 'Updates all local modules with their remote changes (!!you will lose all untracked branches and work!!)'),
array('--addmergedriver', 'Updates/Adds Relevant Merge Drivers'),
array('--switch=<branch>', 'Switch all local modules to branch'),
Expand Down Expand Up @@ -233,15 +234,22 @@
}

if(isset($options['refresh'])) {
// --force (or -y) forces tag updates without prompting. Otherwise ask once
// upfront whether to force automatically or be asked on each conflict.
$force = isset($options['force']) || isset($options['y']);
if(!$force) {
$answer = freepbx::getInput("On tag conflicts, force tag updates automatically? (y = always force / n = ask for each repo)", 'n');
$force = (strtolower(trim($answer)) == 'y');
}
foreach(glob($directory."/*", GLOB_ONLYDIR) as $dir) {
freepbx::refreshRepo($dir);
freepbx::refreshRepo($dir,'origin',null,false,$force);
}
exit(0);
}

if(isset($options['refreshhard'])) {
foreach(glob($directory."/*", GLOB_ONLYDIR) as $dir) {
freepbx::refreshRepo($dir,'origin',null,true);
freepbx::refreshRepo($dir,'origin',null,true,true);
}
exit(0);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,9 @@ public function merge($branch) {
* @access public
* @return string
*/
public function fetch() {
public function fetch($force = false) {
$this->run("fetch -q");
$this->run("fetch --tags -q");
$this->run("fetch --tags -q" . ($force ? " --force" : ""));
return true;
}

Expand Down
26 changes: 23 additions & 3 deletions libraries/freepbx.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,26 @@ public static function switchBranch($directory,$branch) {
$repo->clean(true,true);
freepbx::out("Done");
freepbx::outn("\tFetching Changes...");
$repo->fetch();
freepbx::out("Done");
try {
$repo->fetch();
freepbx::out("Done");
} catch (Exception $e) {
// A plain "fetch --tags" aborts with "would clobber existing tag"
// when a remote tag has been moved/recreated. Force only if told to,
// otherwise ask before forcing.
freepbx::out("Failed");
if(!$force) {
$answer = freepbx::getInput("\tFetch failed (a remote tag may have been moved). Force update of local tags? (y/n)", 'n');
$force = (strtolower(trim($answer)) == 'y');
}
if($force) {
freepbx::outn("\tForcing tag update...");
$repo->fetch(true);
freepbx::out("Done");
} else {
freepbx::out("\tError: unable to fetch, local tags conflict with the remote. Skipping forced update.");
}
}
freepbx::outn("\tChecking out ".$branch." ...");
try {
$repo->checkout($branch);
Expand Down Expand Up @@ -87,9 +105,11 @@ public static function switchBranch($directory,$branch) {
* @param string $directory Location of repo
* @param string $remote The name of the remote origin
* @param string $final_branch The final branch to checkout after updating (null means whatever it was on before)
* @param bool $hard True to reset --hard instead of stashing local changes
* @param bool $force True to force-update local tags on conflict without prompting
* @return bool
*/
public static function refreshRepo($directory, $remote = 'origin', $final_branch = null, $hard = false) {
public static function refreshRepo($directory, $remote = 'origin', $final_branch = null, $hard = false, $force = false) {
$rawname = basename($directory);
if($rawname === 'framework') {
freepbx::out("Refusing to refresh framework as it will break everything. Do it manually");
Expand Down